2015-07-20 00:09:47 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
|
|
if [[ ${EUID} -ne 0 ]]; then
|
|
|
|
|
echo "This script should be run as root." > /dev/stderr
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
if [[ $# == 1 && "$1" == "--check" ]]; then
|
|
|
|
|
echo "OK"
|
|
|
|
|
exit 0
|
|
|
|
|
fi
|
|
|
|
|
|
2017-09-12 21:16:44 -07:00
|
|
|
cmd="$1"
|
2020-01-31 13:33:19 -08:00
|
|
|
metric="$2" # note that this can also be 'cloudron-backup' or appid
|
2017-09-12 21:16:44 -07:00
|
|
|
|
2015-07-24 01:42:28 -07:00
|
|
|
if [[ "${BOX_ENV}" == "cloudron" ]]; then
|
2016-05-10 16:50:28 -07:00
|
|
|
# when restoring the cloudron with many apps, the apptasks rush in to restart
|
|
|
|
|
# collectd which makes systemd/collectd very unhappy and puts the collectd in
|
|
|
|
|
# inactive state
|
2016-05-10 09:51:04 -07:00
|
|
|
for i in {1..10}; do
|
2016-05-10 16:50:28 -07:00
|
|
|
echo "Restarting collectd"
|
|
|
|
|
if systemctl restart collectd; then
|
2017-09-12 21:16:44 -07:00
|
|
|
break
|
2016-05-10 09:51:04 -07:00
|
|
|
fi
|
2016-05-10 16:50:28 -07:00
|
|
|
echo "Failed to reload collectd. Maybe some other apptask is restarting it"
|
|
|
|
|
sleep $((RANDOM%30))
|
2016-05-10 09:51:04 -07:00
|
|
|
done
|
2017-09-12 21:16:44 -07:00
|
|
|
|
|
|
|
|
# delete old stats when uninstalling an app
|
|
|
|
|
if [[ "${cmd}" == "remove" ]]; then
|
2020-01-31 13:33:19 -08:00
|
|
|
echo "Removing collectd stats of ${metric}"
|
2017-09-12 21:16:44 -07:00
|
|
|
|
2018-11-01 20:33:40 -07:00
|
|
|
for i in {1..10}; do
|
2020-01-31 13:33:19 -08:00
|
|
|
if rm -rf ${HOME}/platformdata/graphite/whisper/collectd/localhost/*${metric}*; then
|
2018-11-01 20:33:40 -07:00
|
|
|
break
|
|
|
|
|
fi
|
|
|
|
|
echo "Failed to remove collectd directory. collectd possibly generated data in the middle of removal"
|
|
|
|
|
sleep 3
|
|
|
|
|
done
|
2017-09-12 21:16:44 -07:00
|
|
|
fi
|
2015-07-20 00:09:47 -07:00
|
|
|
fi
|
|
|
|
|
|