Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix systemd service status. #2335

Merged
merged 1 commit into from

3 participants

@jcollie

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.

@jcollie jcollie 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.
d21f011
@thatch45 thatch45 merged commit 81bb247 into from
@herlo
Collaborator
@thatch45
Owner

Thanks for getting this into the package @herlo !

@herlo herlo referenced this pull request from a commit in herlo/salt
@herlo herlo Updating spec to 0.10.4, patching bug #2335 (RHBZ#869669) 48fe835
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 24, 2012
  1. @jcollie

    Fix systemd service status.

    jcollie authored
    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 page is out of date. Refresh to see the latest.
Showing with 4 additions and 9 deletions.
  1. +4 −9 salt/modules/systemd.py
View
13 salt/modules/systemd.py
@@ -166,20 +166,15 @@ def reload(name):
# system
def status(name, sig=None):
'''
- Return the status for a service via systemd, returns the PID if the service
- is running or an empty string if the service is not running
+ Return the status for a service via systemd, returns a bool
+ whether the service is running.
CLI Example::
salt '*' service.status <service name>
'''
- ret = __salt__['cmd.run'](_systemctl_cmd('show', name))
- index1 = ret.find('\nMainPID=')
- index2 = ret.find('\n', index1+9)
- mainpid = ret[index1+9:index2]
- if mainpid == '0':
- return ''
- return mainpid
+ cmd = 'systemctl is-active {0}'.format(name)
+ return not __salt__['cmd.retcode'](cmd)
def enable(name):
Something went wrong with that request. Please try again.