From e1bcb75a714a597eafc0f7b0f23d7e7fe3be11a3 Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Sat, 25 Feb 2012 23:37:48 -0700 Subject: [PATCH] Add initial upstart support for Ubuntu --- salt/modules/service.py | 1 + salt/modules/upstart.py | 76 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 salt/modules/upstart.py diff --git a/salt/modules/service.py b/salt/modules/service.py index 3fd8f8807d..5aee6db4ca 100644 --- a/salt/modules/service.py +++ b/salt/modules/service.py @@ -26,6 +26,7 @@ def __virtual__(): 'Scientific', 'Fedora', 'Gentoo', + 'Ubuntu', 'FreeBSD', 'Windows', ] diff --git a/salt/modules/upstart.py b/salt/modules/upstart.py new file mode 100644 index 0000000000..6135050e70 --- /dev/null +++ b/salt/modules/upstart.py @@ -0,0 +1,76 @@ +''' +Module for the management of upstart systems. The Upstart system only supports +service starting, stopping and restarting. + +DO NOT use this module on red hat systems, as red hat systems should use the +rh_service module, since red hat systems support chkconfig +''' + +import os + + +def __virtual__(): + ''' + Only work on Ubuntu + ''' + # Disable on these platforms, specific service modules exist: + if __grains__['os'] == 'Ubuntu': + return 'service' + return False + + +def _runlevel(): + ''' + Return the current runlevel + ''' + out = __salt__['cmd.run']('runlevel').strip() + return out.split()[1] + + +def start(name): + ''' + Start the specified service + + CLI Example:: + + salt '*' service.start + ''' + cmd = 'service {0} start'.format(name) + return not __salt__['cmd.retcode'](cmd) + + +def stop(name): + ''' + Stop the specified service + + CLI Example:: + + salt '*' service.stop + ''' + cmd = 'service {0} stop'.format(name) + return not __salt__['cmd.retcode'](cmd) + + +def restart(name): + ''' + Restart the named service + + CLI Example:: + + salt '*' service.restart + ''' + cmd = 'service {0} restart'.format(name) + return not __salt__['cmd.retcode'](cmd) + + +def status(name, sig=None): + ''' + Return the status for a service, returns a bool whether the service is + running. + + CLI Example:: + + salt '*' service.status + ''' + cmd = 'service {0} status'.format(name) + return not __salt__['cmd.retcode'](cmd)