diff options
author | Jeffrey C. Ollie <jeff@ocjtech.us> | 2011-04-19 16:34:58 -0500 |
---|---|---|
committer | Jeffrey C. Ollie <jeff@ocjtech.us> | 2011-04-19 16:34:58 -0500 |
commit | 20974e1311168b75e621cad14894fe7b217b61a2 (patch) | |
tree | a2df7d44a6e6ce629bbc13153eec8f3c676c2f89 /src | |
parent | fe0076bb34aaf77b773c0951e2b5141af2d08331 (diff) | |
download | bcfg2-20974e1311168b75e621cad14894fe7b217b61a2.tar.gz bcfg2-20974e1311168b75e621cad14894fe7b217b61a2.tar.bz2 bcfg2-20974e1311168b75e621cad14894fe7b217b61a2.zip |
Add basic support for systemd services.
To use, add "Systemd" to the "drivers" option in the "client" section
of bcfg2.conf on the client. Then, define services on the server like
this:
<Service name="rabbitmq-server" status="on" reload="restart" type="systemd"/>
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Client/Tools/Systemd.py | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/lib/Client/Tools/Systemd.py b/src/lib/Client/Tools/Systemd.py new file mode 100644 index 000000000..e3f6a4169 --- /dev/null +++ b/src/lib/Client/Tools/Systemd.py @@ -0,0 +1,59 @@ +# This is the bcfg2 support for systemd + +"""This is systemd support.""" + +import Bcfg2.Client.Tools +import Bcfg2.Client.XML + +class Systemd(Bcfg2.Client.Tools.SvcTool): + """Systemd support for Bcfg2.""" + name = 'Systemd' + __execs__ = ['/bin/systemctl'] + __handles__ = [('Service', 'systemd')] + __req__ = {'Service': ['name', 'status']} + + def get_svc_command(self, service, action): + return "/bin/systemctl %s %s.service" % (action, service.get('name')) + + def VerifyService(self, entry, _): + """Verify Service status for entry.""" + cmd = "/bin/systemctl status %s.service " % (entry.get('name')) + raw = ''.join(self.cmd.run(cmd)[1]) + + if raw.find('Loaded: error') >= 0: + entry.set('current_status', 'off') + status = False + + elif raw.find('Active: active') >= 0: + entry.set('current_status', 'on') + if entry.get('status') == 'off': + status = False + else: + status = True + + else: + entry.set('current_status', 'off') + if entry.get('status') == 'on': + status = False + else: + status = True + + return status + + def InstallService(self, entry): + """Install Service entry.""" + # don't take any actions for mode = 'manual' + if entry.get('mode', 'default') == 'manual': + self.logger.info("Service %s mode set to manual. Skipping " + "installation." % (entry.get('name'))) + return True + + if entry.get('status') == 'on': + pstatus = self.cmd.run(self.get_svc_command(entry, 'enable'))[0] + pstatus = self.cmd.run(self.get_svc_command(entry, 'start'))[0] + + else: + pstatus = self.cmd.run(self.get_svc_command(entry, 'stop'))[0] + pstatus = self.cmd.run(self.get_svc_command(entry, 'disable'))[0] + + return not pstatus |