From b0b03ee29df3f46b71d9e8b2687af3ed16fd6c76 Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Mon, 12 Dec 2016 07:14:02 -0500 Subject: [PATCH 1/6] added initial support for simpleinit-msb --- lib/ansible/modules/system/service.py | 67 ++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index 6c57441..b8c2048 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -32,7 +32,7 @@ short_description: Manage services. description: - Controls services on remote hosts. Supported init systems include BSD init, - OpenRC, SysV, Solaris SMF, systemd, upstart. + OpenRC, SysV, Solaris SMF, systemd, upstart, simpleinit-msb. options: name: required: true @@ -439,7 +439,7 @@ class LinuxService(Service): def get_service_tools(self): paths = [ '/sbin', '/usr/sbin', '/bin', '/usr/bin' ] - binaries = [ 'service', 'chkconfig', 'update-rc.d', 'rc-service', 'rc-update', 'initctl', 'systemctl', 'start', 'stop', 'restart', 'insserv' ] + binaries = [ 'service', 'chkconfig', 'update-rc.d', 'rc-service', 'rc-update', 'initctl', 'telinit', 'systemctl', 'start', 'stop', 'restart', 'insserv' ] initpaths = [ '/etc/init.d' ] location = dict() @@ -482,6 +482,10 @@ def check_systemd(): self.svc_cmd = location['systemctl'] self.enable_cmd = location['systemctl'] + elif location.get('telinit', False) and os.path.exists("/etc/init.d/smgl_init"): + self.svc_cmd = location['telinit'] + self.enable_cmd = location['telinit'] + elif location.get('initctl', False) and os.path.exists("/etc/init/%s.conf" % self.name): # service is managed by upstart self.enable_cmd = location['initctl'] @@ -887,6 +891,44 @@ def write_to_override_file(file_name, file_contents, ): return (rc, out, err) # + # telinit (Source Mage GNU/Linux) + # + if self.enable_cmd.endswith("telinit"): + (rc, out, err) = self.execute_command("%s list" % self.enable_cmd) + + service_exists = False + + rex = re.compile('^\w+\s+%s$' % self.name) + + for line in out.splitlines(): + if rex.match(line): + service_exists = True + break + + if not service_exists: + self.module.fail_json(msg='telinit could not find the requested service: %s' % self.name) + + if self.enable: + action = "bootenable" + else: + action = "bootdisable" + + (rc, out, err) = self.execute_command("%s %s %s" % (self.enable_cmd, action, self.name)) + + for line in err.splitlines(): + if self.enable and line.find('already enabled') != -1: + self.changed = False + break + if not self.enable and line.find('already disabled') != -1: + self.changed = False + break + + if not self.changed: + return + + return (rc, out, err) + + # # If we've gotten to the end, the service needs to be updated # self.changed = True @@ -921,8 +963,25 @@ def service_control(self): arguments = self.arguments if self.svc_cmd: if not self.svc_cmd.endswith("systemctl"): - # SysV and OpenRC take the form - svc_cmd = "%s %s" % (self.svc_cmd, self.name) + # telinit + if self.svc_cmd.endswith("telinit"): + (rc, out, err) = self.execute_command("%s list" % self.enable_cmd) + + service_exists = False + + rex = re.compile('^\w+\s+%s$' % self.name) + + for line in out.splitlines(): + if rex.match(line): + service_exists = True + break + + if not service_exists: + self.module.fail_json(msg='telinit could not find the requested service: %s' % self.name) + svc_cmd = "%s run %s" % (self.svc_cmd, self.name) + else: + # SysV and OpenRC take the form + svc_cmd = "%s %s" % (self.svc_cmd, self.name) else: # systemd commands take the form svc_cmd = self.svc_cmd From bc526134b2fb36835e37aa58735eefeea5a7f3b3 Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Mon, 12 Dec 2016 13:48:53 -0500 Subject: [PATCH 2/6] described basic telinit syntax in the comment --- lib/ansible/modules/system/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index b8c2048..e04a712 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -963,7 +963,7 @@ def service_control(self): arguments = self.arguments if self.svc_cmd: if not self.svc_cmd.endswith("systemctl"): - # telinit + # telinit takes the form run if self.svc_cmd.endswith("telinit"): (rc, out, err) = self.execute_command("%s list" % self.enable_cmd) From a90989c47e5e257dbc9ed8d3f30ef5c6d5dbb6d7 Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Mon, 12 Dec 2016 13:50:02 -0500 Subject: [PATCH 3/6] missing newline --- lib/ansible/modules/system/service.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index e04a712..a1585cd 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -978,6 +978,7 @@ def service_control(self): if not service_exists: self.module.fail_json(msg='telinit could not find the requested service: %s' % self.name) + svc_cmd = "%s run %s" % (self.svc_cmd, self.name) else: # SysV and OpenRC take the form From 98c6f06ba21169d2852fa1cdb1b9b54efe018f45 Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Fri, 23 Dec 2016 21:00:17 -0500 Subject: [PATCH 4/6] Add 'service_mgr' fact --- lib/ansible/module_utils/facts.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index ca5120a..58d74f6 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -392,6 +392,8 @@ def get_service_mgr_facts(self): elif self.facts['system'] == 'Linux': if self.is_systemd_managed(): self.facts['service_mgr'] = 'systemd' + elif self.module.get_bin_path('telinit') and os.path.exists("/etc/init.d/smgl_init"): + self.facts['service_mgr'] = 'simpleinit' elif self.module.get_bin_path('initctl') and os.path.exists("/etc/init/"): self.facts['service_mgr'] = 'upstart' elif os.path.exists('/sbin/openrc'): From 11fdcfd5fe318586ea4a2f4b1407498ae9aad07b Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Thu, 2 Feb 2017 06:30:00 -0500 Subject: [PATCH 5/6] Correct word-wrap for binaries array --- lib/ansible/modules/system/service.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index a1585cd..e0aa9b1 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -439,7 +439,8 @@ class LinuxService(Service): def get_service_tools(self): paths = [ '/sbin', '/usr/sbin', '/bin', '/usr/bin' ] - binaries = [ 'service', 'chkconfig', 'update-rc.d', 'rc-service', 'rc-update', 'initctl', 'telinit', 'systemctl', 'start', 'stop', 'restart', 'insserv' ] + binaries = [ 'service', 'chkconfig', 'update-rc.d', 'rc-service', 'rc-update', 'initctl', 'telinit', 'systemctl', 'start', 'stop', 'restart', + 'insserv' ] initpaths = [ '/etc/init.d' ] location = dict() From a830294c58ce3f4373ce43cb35b0e5f6bb7c2fa6 Mon Sep 17 00:00:00 2001 From: Vlad Glagolev Date: Mon, 27 Mar 2017 22:02:41 -0400 Subject: [PATCH 6/6] Fix init system comment: it's simpleinit-msb, telinit is a script --- lib/ansible/modules/system/service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ansible/modules/system/service.py b/lib/ansible/modules/system/service.py index e0aa9b1..f464c5c 100644 --- a/lib/ansible/modules/system/service.py +++ b/lib/ansible/modules/system/service.py @@ -892,7 +892,7 @@ def write_to_override_file(file_name, file_contents, ): return (rc, out, err) # - # telinit (Source Mage GNU/Linux) + # simpleinit-msb (Source Mage GNU/Linux) # if self.enable_cmd.endswith("telinit"): (rc, out, err) = self.execute_command("%s list" % self.enable_cmd) .