cluster-deployment/src/steps-postinstall/20-collectd.sh
Starbeamrainbowlabs 6cf5496c69
Add system to tell if we've provisioned before or not
In theory, we can do a one-click "update" with all the same settings as 
we used previously
2022-04-10 18:06:06 +01:00

33 lines
1.1 KiB
Bash
Executable file

#!/usr/bin/env bash
collectd_conf_target="/etc/collectd/collectd.conf";
task_begin "Configurating collectd";
subtask_begin "Stopping collectd";
systemctl stop collectd;
subtask_end "$?";
# If there's an existing config file and we haven't completed provisioning at
# least once yet, move it aside as a backup
if [[ -r "/etc/collectd/collectd.conf" ]] && [[ -z "${last_version}" ]]; then
subtask_begin "Moving existing config file aside";
mv "${collectd_conf_target}" "${collectd_conf_target}.bak-$(date +%Y-%m-%d)";
subtask_end "$?";
fi
subtask_begin "Installing configuration file";
touch "${collectd_conf_target}";
chmod 0600 "${collectd_conf_target}";
#shellcheck disable=SC2154
cat configs/collectd.conf | awk -v "user=${collectd_username}" -v "pass=${collectd_password}" '{ gsub("|||USERNAME|||", user); gsub("|||PASSWORD|||", pass); print }' >"${collectd_conf_target}";
subtask-end "$?";
subtask_begin "Starting collectd & enabling on boot";
systemctl enable --now collectd;
subtask_end "$?";
subtask_begin "Cleaning up";
unset collectd_username collectd_password;
subtask_end "$?";