def service_running(service_name, **kwargs):
    """Determine whether a system service is running.

    :param service_name: the name of the service
    :param **kwargs: additional args to pass to the service command. This is
                     used to pass additional key=value arguments to the
                     service command line for managing specific instance
                     units (e.g. service ceph-osd status id=2). The kwargs
                     are ignored in systemd services.
    """
    if init_is_systemd():
        return service('is-active', service_name)
    else:
        if os.path.exists(_UPSTART_CONF.format(service_name)):
            try:
                cmd = ['status', service_name]
                for key, value in six.iteritems(kwargs):
                    parameter = '%s=%s' % (key, value)
                    cmd.append(parameter)
                output = subprocess.check_output(
                    cmd, stderr=subprocess.STDOUT).decode('UTF-8')
            except subprocess.CalledProcessError:
                return False
            else:
                # This works for upstart scripts where the 'service' command
                # returns a consistent string to represent running
                # 'start/running'
                if ("start/running" in output or
                        "is running" in output or
                        "up and running" in output):
                    return True
        elif os.path.exists(_INIT_D_CONF.format(service_name)):
            # Check System V scripts init script return codes
            return service('status', service_name)
        return False
def service_running ( service_name , ** kwargs ) : if init_is_systemd ( ) : return service ( 'is-active' , service_name ) else : if os . path . exists ( _UPSTART_CONF . format ( service_name ) ) : try : cmd = [ 'status' , service_name ] for key , value in six . iteritems ( kwargs ) : parameter = '%s=%s' % ( key , value ) cmd . append ( parameter ) output = subprocess . check_output ( cmd , stderr = subprocess . STDOUT ) . decode ( 'UTF-8' ) except subprocess . CalledProcessError : return False else : if ( "start/running" in output or "is running" in output or "up and running" in output ) : return True elif os . path . exists ( _INIT_D_CONF . format ( service_name ) ) : return service ( 'status' , service_name ) return False
Determine whether a system service is running.

    :param service_name: the name of the service
    :param **kwargs: additional args to pass to the service command. This is
                     used to pass additional key=value arguments to the
                     service command line for managing specific instance
                     units (e.g. service ceph-osd status id=2). The kwargs
                     are ignored in systemd services.