summaryrefslogtreecommitdiff
path: root/heat_cfntools/cfntools
diff options
context:
space:
mode:
authorEthan Lynn <xjunlin@cn.ibm.com>2014-05-12 15:38:29 +0800
committerEthan Lynn <xjunlin@cn.ibm.com>2014-05-29 17:38:39 +0800
commit0fab4170ffa33dc1628f50972fa21862d844a618 (patch)
tree2de2c6555dba41cca93b8b449d6ab0d32c5ab469 /heat_cfntools/cfntools
parentcd39c89a80eed1bbb2515cca5b088ca686daab3e (diff)
downloadheat-cfntools-0fab4170ffa33dc1628f50972fa21862d844a618.tar.gz
Update sysvinit function to support ubuntu
In ubuntu system, we can't find 'chkconfig' command, it use "update-rc.d" or "sysv-rc-conf" for instead. _handle_sysv_command function will pick up the right command to enable service for ubuntu or fedora or redhat, and also map systemd to _handle_sysv_command and remove _handle_systemd_command. Change-Id: I5b7ceb7541e989f6b11fc1a5acf94275c1d2e75b Closes-Bug: #1318481
Diffstat (limited to 'heat_cfntools/cfntools')
-rw-r--r--heat_cfntools/cfntools/cfn_helper.py60
1 files changed, 35 insertions, 25 deletions
diff --git a/heat_cfntools/cfntools/cfn_helper.py b/heat_cfntools/cfntools/cfn_helper.py
index b5dd5b4..4085a43 100644
--- a/heat_cfntools/cfntools/cfn_helper.py
+++ b/heat_cfntools/cfntools/cfn_helper.py
@@ -643,37 +643,47 @@ class ServicesHandler(object):
self.hooks = hooks
def _handle_sysv_command(self, service, command):
- service_exe = "/sbin/service"
- enable_exe = "/sbin/chkconfig"
- cmd = ""
- if "enable" == command:
- cmd = "%s %s on" % (enable_exe, service)
- elif "disable" == command:
- cmd = "%s %s off" % (enable_exe, service)
- elif "start" == command:
- cmd = "%s %s start" % (service_exe, service)
- elif "stop" == command:
- cmd = "%s %s stop" % (service_exe, service)
- elif "status" == command:
- cmd = "%s %s status" % (service_exe, service)
- command = CommandRunner(cmd)
- command.run()
- return command
+ if os.path.exists("/bin/systemctl"):
+ service_exe = "/bin/systemctl"
+ service = '%s.service' % service
+ service_start = '%s start %s'
+ service_status = '%s status %s'
+ service_stop = '%s stop %s'
+ elif os.path.exists("/sbin/service"):
+ service_exe = "/sbin/service"
+ service_start = '%s %s start'
+ service_status = '%s %s status'
+ service_stop = '%s %s stop'
+ else:
+ service_exe = "/usr/sbin/service"
+ service_start = '%s %s start'
+ service_status = '%s %s status'
+ service_stop = '%s %s stop'
+
+ if os.path.exists("/bin/systemctl"):
+ enable_exe = "/bin/systemctl"
+ enable_on = '%s enable %s'
+ enable_off = '%s disable %s'
+ elif os.path.exists("/sbin/chkconfig"):
+ enable_exe = "/sbin/chkconfig"
+ enable_on = '%s %s on'
+ enable_off = '%s %s off'
+ else:
+ enable_exe = "/usr/sbin/update-rc.d"
+ enable_on = '%s %s enable'
+ enable_off = '%s %s disable'
- def _handle_systemd_command(self, service, command):
- exe = "/bin/systemctl"
cmd = ""
- service = '%s.service' % service
if "enable" == command:
- cmd = "%s enable %s" % (exe, service)
+ cmd = enable_on % (enable_exe, service)
elif "disable" == command:
- cmd = "%s disable %s" % (exe, service)
+ cmd = enable_off % (enable_exe, service)
elif "start" == command:
- cmd = "%s start %s" % (exe, service)
+ cmd = service_start % (service_exe, service)
elif "stop" == command:
- cmd = "%s stop %s" % (exe, service)
+ cmd = service_stop % (service_exe, service)
elif "status" == command:
- cmd = "%s status %s" % (exe, service)
+ cmd = service_status % (service_exe, service)
command = CommandRunner(cmd)
command.run()
return command
@@ -725,7 +735,7 @@ class ServicesHandler(object):
# map of function pointers to various service handlers
_service_handlers = {
"sysvinit": _handle_sysv_command,
- "systemd": _handle_systemd_command
+ "systemd": _handle_sysv_command
}
def _service_handler(self, manager_name):