mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Fix systemd service status.
Under systemd, not every service has a "Main PID" so using that to determine whether a service was running failed for a number of useful cases, especially services that use systemd's init script compatibility layer. Instead, use the 'systemctl is-active' command to determine the status of a service.
This commit is contained in:
parent
0bc4d05f31
commit
d21f01128f
@ -166,20 +166,15 @@ def reload(name):
|
|||||||
# system
|
# system
|
||||||
def status(name, sig=None):
|
def status(name, sig=None):
|
||||||
'''
|
'''
|
||||||
Return the status for a service via systemd, returns the PID if the service
|
Return the status for a service via systemd, returns a bool
|
||||||
is running or an empty string if the service is not running
|
whether the service is running.
|
||||||
|
|
||||||
CLI Example::
|
CLI Example::
|
||||||
|
|
||||||
salt '*' service.status <service name>
|
salt '*' service.status <service name>
|
||||||
'''
|
'''
|
||||||
ret = __salt__['cmd.run'](_systemctl_cmd('show', name))
|
cmd = 'systemctl is-active {0}'.format(name)
|
||||||
index1 = ret.find('\nMainPID=')
|
return not __salt__['cmd.retcode'](cmd)
|
||||||
index2 = ret.find('\n', index1+9)
|
|
||||||
mainpid = ret[index1+9:index2]
|
|
||||||
if mainpid == '0':
|
|
||||||
return ''
|
|
||||||
return mainpid
|
|
||||||
|
|
||||||
|
|
||||||
def enable(name):
|
def enable(name):
|
||||||
|
Loading…
Reference in New Issue
Block a user