ubuntu 16.04 systemctl service config
        :param service_name:
        :param start_cmd:
        :param stop_cmd:
        :return:
452
def systemctl_autostart(self, service_name, start_cmd, stop_cmd):
        
        # get config content
        service_content = bigdata_conf.systemctl_config.format(
            service_name=service_name,
            start_cmd=start_cmd,
            stop_cmd=stop_cmd
        )

        # write config into file
        with cd('/lib/systemd/system'):
            if not exists(service_name):
                sudo('touch {0}'.format(service_name))
            put(StringIO(service_content), service_name, use_sudo=True)

        # make service auto-start
        sudo('systemctl daemon-reload')
        sudo('systemctl disable {0}'.format(service_name))
        sudo('systemctl stop {0}'.format(service_name))
        sudo('systemctl enable {0}'.format(service_name))
        sudo('systemctl start {0}'.format(service_name))
442985
def service_start(name):
    '''
    
    '''
    cmd = 'start ' + name

    # Send the command to execute
    out, err = DETAILS['server'].sendline(cmd)

    # "scrape" the output and return the right fields as a dict
    return parse(out)
65730
def _service_is_sysv(name):
    '''
    
    '''
    script = '/etc/init.d/{0}'.format(name)
    return not _service_is_upstart(name) and os.access(script, os.X_OK)
1053461
def disable_service(conn, service='ceph'):
    
    if is_systemd(conn):
        # Without the check, an error is raised trying to disable an
        # already disabled service
        if is_systemd_service_enabled(conn, service):
            remoto.process.run(
                conn,
                [
                    'systemctl',
                    'disable',
                    '{service}'.format(service=service),
                ]
            )
744813
def service_enable(s_name, **connection_args):
    '''
    
    '''
    ret = True
    service = _service_get(s_name, **connection_args)
    if service is None:
        return False
    nitro = _connect(**connection_args)
    if nitro is None:
        return False
    try:
        NSService.enable(nitro, service)
    except NSNitroError as error:
        log.debug('netscaler module error - NSService.enable() failed: %s', error)
        ret = False
    _disconnect(nitro)
    return ret
409254
def add_firewalld_service(service, permanent=True):
    
    yum_install(packages=['firewalld'])

    with settings(hide('warnings', 'running', 'stdout', 'stderr'),
                  warn_only=True, capture=True):
        p = ''
        if permanent:
            p = '--permanent'
        sudo('firewall-cmd --add-service %s %s' % (service, p))
        sudo('systemctl reload firewalld')
150080
def show(name):
    '''
    
    '''
    ret = {}
    ret['enabled'] = False
    ret['disabled'] = True
    ret['running'] = False
    ret['service_path'] = None
    ret['autostart'] = False
    ret['command_path'] = None

    ret['available'] = available(name)
    if not ret['available']:
        return ret

    ret['enabled'] = enabled(name)
    ret['disabled'] = not ret['enabled']
    ret['running'] = status(name)
    ret['autostart'] = status_autostart(name)
    ret['service_path'] = _get_svc_path(name)[0]
    if ret['service_path']:
        ret['command_path'] = os.path.join(ret['service_path'], 'run')

    # XXX provide info about alias ?

    return ret
170861
def _systemctl_cmd(action, name=None, systemd_scope=False, no_block=False,
                   root=None):
    '''
    
    '''
    ret = []
    if systemd_scope \
            and salt.utils.systemd.has_scope(__context__) \
            and __salt__['config.get']('systemd.scope', True):
        ret.extend(['systemd-run', '--scope'])
    ret.append('systemctl')
    if no_block:
        ret.append('--no-block')
    if root:
        ret.extend(['--root', root])
    if isinstance(action, six.string_types):
        action = shlex.split(action)
    ret.extend(action)
    if name is not None:
        ret.append(_canonical_unit_name(name))
    if 'status' in ret:
        ret.extend(['-n', '0'])
    return ret
125304
def do_start_service(self, service):
        
        if not self.has_cluster():
            return None

        if self.service_action(service=service, action="start"):
            print("%s is being started" % (service))
        else:
            print("Error starting service")
            return None
819637
def stop(name):
    '''
    
    '''
    if _service_is_upstart(name):
        cmd = 'stop {0}'.format(name)
    else:
        cmd = '/sbin/service {0} stop'.format(name)
    return not __salt__['cmd.retcode'](cmd, python_shell=False)
547877
def do_restart_service(self, service):
        
        if not self.has_cluster():
            return None

        if self.service_action(service=service, action="restart"):
            print("%s is being restarted" % (service))
        else:
            print("Error restarting service")
            return None
764519
def get_enabled():
    '''
    
    '''
    ret = set()
    for name in _iter_service_names():
        if _service_is_upstart(name):
            if _upstart_is_enabled(name):
                ret.add(name)
        else:
            if _service_is_sysv(name):
                if _sysv_is_enabled(name):
                    ret.add(name)
    return sorted(ret)
432624
def _service_is_chkconfig(name):
    '''
    
    '''
    cmdline = '/sbin/chkconfig --list {0}'.format(name)
    return __salt__['cmd.retcode'](cmdline, python_shell=False, ignore_retcode=True) == 0
94040
def disabled(name):
    '''
    
    '''
    if _service_is_upstart(name):
        return _upstart_is_disabled(name)
    else:
        if _service_is_sysv(name):
            return _sysv_is_disabled(name)
    return None
1003459
def _StartSshd(self):
    """"""
    # Exit as early as possible.
    # Instance setup systemd scripts block sshd from starting.
    if os.path.exists(constants.LOCALBASE + '/bin/systemctl'):
      return
    elif (os.path.exists('/etc/init.d/ssh')
          or os.path.exists('/etc/init/ssh.conf')):
      subprocess.call(['service', 'ssh', 'start'])
      subprocess.call(['service', 'ssh', 'reload'])
    elif (os.path.exists('/etc/init.d/sshd')
          or os.path.exists('/etc/init/sshd.conf')):
      subprocess.call(['service', 'sshd', 'start'])
      subprocess.call(['service', 'sshd', 'reload'])
874578
def start(name):
    '''
    
    '''
    cmd = '/usr/sbin/svcadm enable -s -t {0}'.format(name)
    retcode = __salt__['cmd.retcode'](cmd, python_shell=False)
    if not retcode:
        return True
    if retcode == 3:
        # Return code 3 means there was a problem with the service
        # A common case is being in the 'maintenance' state
        # Attempt a clear and try one more time
        clear_cmd = '/usr/sbin/svcadm clear {0}'.format(name)
        __salt__['cmd.retcode'](clear_cmd, python_shell=False)
        return not __salt__['cmd.retcode'](cmd, python_shell=False)
    return False
1298978
def restart(self, name):
        
        init = self._get_implementation(name)
        self._assert_service_installed(init, name)
        logger.info('Restarting service: %s...', name)
        init.stop()
        # Here we would use status to verify that the service stopped
        # before restarting. If only status was stable. eh..
        # The arbitrarity of this sleep time is making me sick...
        time.sleep(3)
        init.start()