parent
e559498b43
commit
0beb7db793
@ -0,0 +1,48 @@
|
|||||||
|
From d21f01128f378cd9bbcf59e7436114594ddf08e4 Mon Sep 17 00:00:00 2001
|
||||||
|
From: "Jeffrey C. Ollie" <jeff@ocjtech.us>
|
||||||
|
Date: Tue, 23 Oct 2012 09:20:38 -0500
|
||||||
|
Subject: [PATCH] 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.
|
||||||
|
---
|
||||||
|
salt/modules/systemd.py | 13 ++++---------
|
||||||
|
1 file changed, 4 insertions(+), 9 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/salt/modules/systemd.py b/salt/modules/systemd.py
|
||||||
|
index 2e37718..185b1d5 100644
|
||||||
|
--- a/salt/modules/systemd.py
|
||||||
|
+++ b/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):
|
||||||
|
--
|
||||||
|
1.7.11.7
|
||||||
|
|
Loading…
Reference in new issue