summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Coca <brian.coca+git@gmail.com>2015-10-23 18:59:05 -0400
committerBrian Coca <brian.coca+git@gmail.com>2015-10-23 18:59:05 -0400
commit4072bc1da0010750d7d7dee32a9bd00d5222cc6e (patch)
treef020ff69a44190deb3e8f735dc2377420c408df5
parentdae3718e794951f6b3da031e7a26a29f5077a2dc (diff)
downloadansible-modules-core-4072bc1da0010750d7d7dee32a9bd00d5222cc6e.tar.gz
rearranged systemd check, removed redundant systemctl check
fixed unused cmd and state var assignements
-rw-r--r--system/service.py31
1 files changed, 26 insertions, 5 deletions
diff --git a/system/service.py b/system/service.py
index d08b6cd6..2b8dbb86 100644
--- a/system/service.py
+++ b/system/service.py
@@ -395,7 +395,7 @@ class LinuxService(Service):
location = dict()
for binary in binaries:
- location[binary] = self.module.get_bin_path(binary)
+ location[binary] = self.module.get_bin_path(binary, opt_dirs=paths)
for initdir in initpaths:
initscript = "%s/%s" % (initdir,self.name)
@@ -403,10 +403,31 @@ class LinuxService(Service):
self.svc_initscript = initscript
def check_systemd():
- return os.path.exists("/run/systemd/system/") or os.path.exists("/dev/.run/systemd/") or os.path.exists("/dev/.systemd/")
+
+ # tools must be installed
+ if location.get('systemctl',False):
+
+ # this should show if systemd is the boot init system
+ # these mirror systemd's own sd_boot test http://www.freedesktop.org/software/systemd/man/sd_booted.html
+ for canary in ["/run/systemd/system/", "/dev/.run/systemd/", "/dev/.systemd/"]:
+ if os.path.exists(canary):
+ return True
+
+ # If all else fails, check if init is the systemd command, using comm as cmdline could be symlink
+ try:
+ f = open('/proc/1/comm', 'r')
+ except IOError:
+ # If comm doesn't exist, old kernel, no systemd
+ return False
+
+ for line in f:
+ if 'systemd' in line:
+ return True
+
+ return False
# Locate a tool to enable/disable a service
- if location.get('systemctl',False) and check_systemd():
+ if check_systemd():
# service is managed by systemd
self.__systemd_unit = self.name
self.svc_cmd = location['systemctl']
@@ -684,7 +705,8 @@ class LinuxService(Service):
(rc, out, err) = self.execute_command("%s --list %s" % (self.enable_cmd, self.name))
if not self.name in out:
self.module.fail_json(msg="service %s does not support chkconfig" % self.name)
- state = out.split()[-1]
+ #TODO: look back on why this is here
+ #state = out.split()[-1]
# Check if we're already in the correct state
if "3:%s" % action in out and "5:%s" % action in out:
@@ -946,7 +968,6 @@ class FreeBsdService(Service):
self.rcconf_file = rcfile
rc, stdout, stderr = self.execute_command("%s %s %s %s" % (self.svc_cmd, self.name, 'rcvar', self.arguments))
- cmd = "%s %s %s %s" % (self.svc_cmd, self.name, 'rcvar', self.arguments)
try:
rcvars = shlex.split(stdout, comments=True)
except: