Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support systemd native services in the service module. #944

Merged
merged 2 commits into from
Aug 25, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 17 additions & 9 deletions library/service
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def _find_binaries(m):
global CHKCONFIG
global INITCTL
paths = ['/sbin', '/usr/sbin', '/bin', '/usr/bin']
binaries = [ 'service', 'chkconfig', 'update-rc.d', 'initctl']
binaries = [ 'service', 'chkconfig', 'update-rc.d', 'initctl', 'systemctl']
location = dict()

for binary in binaries:
Expand All @@ -44,7 +44,9 @@ def _find_binaries(m):
location[binary] = path + '/' + binary
break

if location.get('chkconfig', None):
if location.get('systemctl', None):
CHKCONFIG = location['systemctl']
elif location.get('chkconfig', None):
CHKCONFIG = location['chkconfig']
elif location.get('update-rc.d', None):
CHKCONFIG = location['update-rc.d']
Expand Down Expand Up @@ -142,17 +144,23 @@ def _do_enable(name, enable):
# we change argument depending on real binary used
# update-rc.d wants enable/disable while
# chkconfig wants on/off
valid_argument = dict({'on' : 'on', 'off' : 'off'})
# also, systemctl needs the arguments reversed
if enable:
on_off = "on"
enable_disable = "enable"
else:
on_off = "off"
enable_disable = "disable"

if CHKCONFIG.endswith("update-rc.d"):
valid_argument['on'] = "enable"
valid_argument['off'] = "disable"
args = (CHKCONFIG, name, enable_disable)
elif CHKCONFIG.endswith("systemctl"):
args = (CHKCONFIG, enable_disable, name + ".service")
else:
args = (CHKCONFIG, name, on_off)

if enable is not None:
if enable:
rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['on']))
else:
rc, stdout, stderr = _run("%s %s %s" % (CHKCONFIG, name, valid_argument['off']))
rc, stdout, stderr = _run("%s %s %s" % args)

return rc, stdout, stderr

Expand Down