From 6720d0cf707184ba8fed3441c7b334654ba6b612 Mon Sep 17 00:00:00 2001 From: cdigiovanni Date: Mon, 30 Sep 2013 14:50:47 -0500 Subject: [PATCH] Added support to disable and enable upstart jobs --- system/service | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/system/service b/system/service index 114f6271e58..478a59a58f3 100644 --- a/system/service +++ b/system/service @@ -430,7 +430,7 @@ class LinuxService(Service): self.enable_cmd = location['systemctl'] elif os.path.exists("/etc/init/%s.conf" % self.name): # service is managed by upstart - self.enable_cmd = location['update-rc.d'] + self.enable_cmd = location['initctl'] elif os.path.exists("/etc/init.d/%s" % self.name): # service is managed by with SysV init scripts, but with update-rc.d self.enable_cmd = location['update-rc.d'] @@ -537,6 +537,37 @@ class LinuxService(Service): # to decide whether to run the command here but need something # similar for upstart + if self.enable_cmd.endswith("initctl"): + def write_to_override_file(file_name, file_contents, ): + override_file = open(file_name, 'w') + override_file.write(file_contents) + override_file.close() + + initpath = '/etc/init' + manreg = re.compile('^manual\s*$', re.M | re.I) + conf_file_name = "%s/%s.conf" % (initpath, self.name) + override_file_name = "%s/%s.override" % (initpath, self.name) + + # Check to see if files contain the manual line in .conf and fail if True + if manreg.search(open(conf_file_name).read()): + self.module.fail_json(msg="manual stanza not supported in a .conf file") + + if os.path.exists(override_file_name): + override_file_contents = open(override_file_name).read() + # Remove manual stanza if present and service enabled + if self.enable and manreg.search(override_file_contents): + write_to_override_file(override_file_name, manreg.sub('', override_file_contents)) + # Add manual stanza if not present and service disabled + elif not (self.enable) and not (manreg.search(override_file_contents)): + write_to_override_file(override_file_name, override_file_contents + '\nmanual\n') + else: + return + # Add file with manual stanza if service disabled + elif not (self.enable): + write_to_override_file(override_file_name, 'manual\n') + else: + return + if self.enable_cmd.endswith("chkconfig"): (rc, out, err) = self.execute_command("%s --list %s" % (self.enable_cmd, self.name)) if 'chkconfig --add %s' % self.name in err: