cluster-deployment/src/steps-postinstall/20-collectd.sh
Starbeamrainbowlabs 7d54bdf5de
Some checks are pending
continuous-integration/laminar-eldarion Build failed with exit code 123 after 3 seconds
20-collectd: fixup
2022-08-06 21:47:09 +01:00

34 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
#shellcheck disable=SC2154
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
awk -v "user=${collectd_username}" -v "pass=${collectd_password}" '{ gsub("\\|\\|\\|USERNAME\\|\\|\\|", user); gsub("\\|\\|\\|PASSWORD\\|\\|\\|", pass); print }' >"${collectd_conf_target}" <"configs/collectd.conf";
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 "$?";