From bdd89db30d84e7a97ae82d0e6d8b73d19373c390 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 19 Feb 2023 10:38:43 -0600 Subject: [PATCH] Add `install_collectd()` function --- rattail_fabric2/collectd.py | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/rattail_fabric2/collectd.py b/rattail_fabric2/collectd.py index 456ebbc..1528825 100644 --- a/rattail_fabric2/collectd.py +++ b/rattail_fabric2/collectd.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,12 +24,44 @@ Fabric library for collectd """ -from rattail_fabric2 import make_deploy +from rattail_fabric2 import apt, make_deploy, sed deploy = make_deploy(__file__) +def install_collectd(c, interval=None, rrdtool=None, restart_=False): + """ + Install the ``collectd`` service. + + :param interval: Optional override for the collectd ``Interval`` + setting. + """ + apt.install(c, 'collectd') + + if interval: + sed(c, '/etc/collectd/collectd.conf', + r'^#? ?Interval\s+[0-9]+.*$', + 'Interval {}'.format(interval), + use_sudo=True) + + if rrdtool is not None: + sed(c, '/etc/collectd/collectd.conf', + r'^#? ?LoadPlugin rrdtool\s*$', + '{}LoadPlugin rrdtool'.format('' if rrdtool else '#'), + use_sudo=True) + + if restart_: + restart(c) + + +def restart(c): + """ + Restart the collectd service. + """ + c.sudo('systemctl restart collectd') + + def deploy_mountpoint_check_script(c, dest, **kwargs): """ Deploy generic mountpoint check script to specified destination.