summaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorJames Cammarata <jimi@sngx.net>2014-08-25 13:41:39 -0500
committerJames Cammarata <jimi@sngx.net>2014-08-25 13:41:39 -0500
commit30d6713bf08807e298a9e14b621dab5745a15e66 (patch)
tree6f1455aaeddd185ba3b383840d3f531f36eb9a9f /system
parent6f8a29dc3d464515a51e4ee5618f3a0d816c5986 (diff)
downloadansible-modules-extras-30d6713bf08807e298a9e14b621dab5745a15e66.tar.gz
Add additional checks to detect upstart services
Also adds checks for the upstart version, in order to test check support for manual vs. start on manual
Diffstat (limited to 'system')
-rw-r--r--system/service33
1 files changed, 30 insertions, 3 deletions
diff --git a/system/service b/system/service
index c2bbb332..c9544c53 100644
--- a/system/service
+++ b/system/service
@@ -105,6 +105,8 @@ import select
import time
import string
+from distutils.version import LooseVersion
+
class Service(object):
"""
This is the generic Service manipulation class that is subclassed
@@ -449,6 +451,26 @@ class LinuxService(Service):
elif check_systemd(self.name):
# service is managed by systemd
self.enable_cmd = location['systemctl']
+ elif location['initctl'] and os.path.exists("/etc/init/%s.conf" % self.name):
+ # service is managed by upstart
+ self.enable_cmd = location['initctl']
+
+ # if this service is managed via upstart, get the current upstart version
+ if self.enable_cmd == location['initctl']:
+ # default the upstart version to something we can compare against
+ self.upstart_version = LooseVersion('0.0.0')
+ try:
+ # set the upstart version based on the output of 'initctl version'
+ version_re = re.compile(r'\(upstart (.*)\)')
+ rc,stdout,stderr = self.module.run_command('initctl version')
+ if rc == 0:
+ res = version_re.search(stdout)
+ if res:
+ self.upstart_version = LooseVersion(res.groups()[0])
+ except:
+ # we'll use the default of 0.0.0 since we couldn't
+ # detect the current upstart version above
+ pass
# Locate a tool for runtime service management (start, stop etc.)
if location.get('service', None) and os.path.exists("/etc/init.d/%s" % self.name):
@@ -576,7 +598,12 @@ class LinuxService(Service):
override_file.close()
initpath = '/etc/init'
- manreg = re.compile('^start on manual\s*$', re.M | re.I)
+ if self.upstart_version >= LooseVersion('0.6.7'):
+ manreg = re.compile('^manual\s*$', re.M | re.I)
+ config_line = 'manual\n'
+ else:
+ manreg = re.compile('^start on manual\s*$', re.M | re.I)
+ config_line = 'start on manual\n'
conf_file_name = "%s/%s.conf" % (initpath, self.name)
override_file_name = "%s/%s.override" % (initpath, self.name)
@@ -591,12 +618,12 @@ class LinuxService(Service):
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 + '\nstart on manual\n')
+ write_to_override_file(override_file_name, override_file_contents + '\n' + config_line)
else:
return
# Add file with manual stanza if service disabled
elif not (self.enable):
- write_to_override_file(override_file_name, 'start on manual\n')
+ write_to_override_file(override_file_name, config_line)
else:
return