summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGordon Messmer <gordon@dragonsdawn.net>2015-02-24 15:04:33 -0800
committerGordon Messmer <gordon@dragonsdawn.net>2015-03-03 13:44:49 -0800
commit16e8783bdd51302521ef37202f115dbec64a32ff (patch)
tree22d50b132db411a6feeb9a58405a85d312f5b025
parentde35c940ca5ec2924fcbd26fe97148defd38701b (diff)
downloadbcfg2-16e8783bdd51302521ef37202f115dbec64a32ff.tar.gz
bcfg2-16e8783bdd51302521ef37202f115dbec64a32ff.tar.bz2
bcfg2-16e8783bdd51302521ef37202f115dbec64a32ff.zip
Improve systemd module so that it resembles more mature modules.
-rw-r--r--src/lib/Bcfg2/Client/Tools/Systemd.py58
1 files changed, 45 insertions, 13 deletions
diff --git a/src/lib/Bcfg2/Client/Tools/Systemd.py b/src/lib/Bcfg2/Client/Tools/Systemd.py
index 3b60c8285..58574f241 100644
--- a/src/lib/Bcfg2/Client/Tools/Systemd.py
+++ b/src/lib/Bcfg2/Client/Tools/Systemd.py
@@ -26,31 +26,63 @@ class Systemd(Bcfg2.Client.Tools.SvcTool):
def get_svc_command(self, service, action):
return "/bin/systemctl %s %s" % (action, self.get_svc_name(service))
+ def verify_bootstatus(self, entry, bootstatus):
+ """Verify bootstatus for entry."""
+ cmd = self.get_svc_command(entry, 'is-enabled')
+ rv = self.cmd.run(cmd)
+
+ if rv.stdout.strip() == 'enabled':
+ return bootstatus == 'on'
+ else:
+ return bootstatus == 'off'
+
def VerifyService(self, entry, _):
"""Verify Service status for entry."""
- if entry.get('status') == 'ignore':
+ entry.set('target_status', entry.get('status')) # for reporting
+
+ bootstatus = self.get_bootstatus(entry)
+ if bootstatus is None:
+ # bootstatus is unspecified and status is ignore
return True
- cmd = "/bin/systemctl status %s" % (self.get_svc_name(entry))
- rv = self.cmd.run(cmd)
+ current_bootstatus = self.verify_bootstatus(entry, bootstatus)
+ if entry.get('status') == 'ignore':
+ return current_bootstatus
- if 'Loaded: error' in rv.stdout:
- entry.set('current_status', 'off')
- return False
- elif 'Active: active' in rv.stdout:
+ cmd = self.get_svc_command(entry, 'show') + ' -p ActiveState'
+ rv = self.cmd.run(cmd)
+ if rv.stdout.strip() in ('ActiveState=active', 'ActiveState=activating',
+ 'ActiveState=reloading'):
entry.set('current_status', 'on')
- return entry.get('status') == 'on'
+ return entry.get('status') == 'on' and current_bootstatus
else:
entry.set('current_status', 'off')
- return entry.get('status') == 'off'
+ return entry.get('status') == 'off' and current_bootstatus
def InstallService(self, entry):
"""Install Service entry."""
- if entry.get('status') == 'on':
+ self.logger.info("Installing Service %s" % (entry.get('name')))
+ bootstatus = self.get_bootstatus(entry)
+ if bootstatus is None:
+ # bootstatus is unspecified and status is ignore
+ return True
+
+ if bootstatus == 'on':
rv = self.cmd.run(self.get_svc_command(entry, 'enable')).success
- rv &= self.cmd.run(self.get_svc_command(entry, 'start')).success
else:
- rv = self.cmd.run(self.get_svc_command(entry, 'stop')).success
- rv &= self.cmd.run(self.get_svc_command(entry, 'disable')).success
+ rv = self.cmd.run(self.get_svc_command(entry, 'disable')).success
+
+ if Bcfg2.Options.setup.servicemode == 'disabled':
+ # 'disabled' means we don't attempt to modify running svcs
+ return rv
+ elif Bcfg2.Options.setup.servicemode == 'build':
+ # 'build' means we attempt to stop all services started
+ if entry.get('current_status') == 'on':
+ rv &= self.cmd.run(self.get_svc_command(entry, 'stop')).success
+ else:
+ if entry.get('status') == 'on':
+ rv &= self.cmd.run(self.get_svc_command(entry, 'start')).success
+ else:
+ rv &= self.cmd.run(self.get_svc_command(entry, 'stop')).success
return rv