diff --git a/setup/start/sudoers b/setup/start/sudoers index 3439d3ad4..99e24fa51 100644 --- a/setup/start/sudoers +++ b/setup/start/sudoers @@ -13,8 +13,8 @@ yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/reloadnginx.sh Defaults!/home/yellowtent/box/src/scripts/reboot.sh env_keep="HOME BOX_ENV" yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/reboot.sh -Defaults!/home/yellowtent/box/src/scripts/reloadcollectd.sh env_keep="HOME BOX_ENV" -yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/reloadcollectd.sh +Defaults!/home/yellowtent/box/src/scripts/configurecollectd.sh env_keep="HOME BOX_ENV" +yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/configurecollectd.sh Defaults!/home/yellowtent/box/src/scripts/collectlogs.sh env_keep="HOME BOX_ENV" yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/collectlogs.sh diff --git a/src/apptask.js b/src/apptask.js index a6c0f6bcd..4919dc9ac 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -56,7 +56,7 @@ var addons = require('./addons.js'), _ = require('underscore'); var COLLECTD_CONFIG_EJS = fs.readFileSync(__dirname + '/collectd.config.ejs', { encoding: 'utf8' }), - RELOAD_COLLECTD_CMD = path.join(__dirname, 'scripts/reloadcollectd.sh'), + CONFIGURE_COLLECTD_CMD = path.join(__dirname, 'scripts/configurecollectd.sh'), LOGROTATE_CONFIG_EJS = fs.readFileSync(__dirname + '/logrotate.ejs', { encoding: 'utf8' }), MV_LOGROTATE_CONFIG_CMD = path.join(__dirname, 'scripts/mvlogrotateconfig.sh'), RM_LOGROTATE_CONFIG_CMD = path.join(__dirname, 'scripts/rmlogrotateconfig.sh'), @@ -162,7 +162,7 @@ function addCollectdProfile(app, callback) { var collectdConf = ejs.render(COLLECTD_CONFIG_EJS, { appId: app.id, containerId: app.containerId }); fs.writeFile(path.join(paths.COLLECTD_APPCONFIG_DIR, app.id + '.conf'), collectdConf, function (error) { if (error) return callback(error); - shell.sudo('addCollectdProfile', [ RELOAD_COLLECTD_CMD ], callback); + shell.sudo('addCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'add', app.id ], callback); }); } @@ -172,7 +172,7 @@ function removeCollectdProfile(app, callback) { fs.unlink(path.join(paths.COLLECTD_APPCONFIG_DIR, app.id + '.conf'), function (error) { if (error && error.code !== 'ENOENT') debugApp(app, 'Error removing collectd profile', error); - shell.sudo('removeCollectdProfile', [ RELOAD_COLLECTD_CMD ], callback); + shell.sudo('removeCollectdProfile', [ CONFIGURE_COLLECTD_CMD, 'remove', app.id ], callback); }); } diff --git a/src/scripts/reloadcollectd.sh b/src/scripts/configurecollectd.sh similarity index 71% rename from src/scripts/reloadcollectd.sh rename to src/scripts/configurecollectd.sh index 52eb88de1..f19a2ca22 100755 --- a/src/scripts/reloadcollectd.sh +++ b/src/scripts/configurecollectd.sh @@ -12,6 +12,9 @@ if [[ $# == 1 && "$1" == "--check" ]]; then exit 0 fi +cmd="$1" +appid="$2" + if [[ "${BOX_ENV}" == "cloudron" ]]; then # 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 @@ -19,10 +22,17 @@ if [[ "${BOX_ENV}" == "cloudron" ]]; then for i in {1..10}; do echo "Restarting collectd" if systemctl restart collectd; then - exit 0 + break fi echo "Failed to reload collectd. Maybe some other apptask is restarting it" sleep $((RANDOM%30)) done + + # delete old stats when uninstalling an app + if [[ "${cmd}" == "remove" ]]; then + echo "Removing collectd stats of ${appid}" + + rm -rf ${HOME}/platformdata/graphite/whisper/collectd/localhost/*${appid}* + fi fi diff --git a/src/test/checkInstall b/src/test/checkInstall index cc9a806d7..6e9bbf035 100755 --- a/src/test/checkInstall +++ b/src/test/checkInstall @@ -15,7 +15,7 @@ scripts=("${SOURCE_DIR}/src/scripts/rmappdir.sh" \ "${SOURCE_DIR}/src/scripts/reboot.sh" \ "${SOURCE_DIR}/src/scripts/update.sh" \ "${SOURCE_DIR}/src/scripts/collectlogs.sh" \ - "${SOURCE_DIR}/src/scripts/reloadcollectd.sh" \ + "${SOURCE_DIR}/src/scripts/configurecollectd.sh" \ "${SOURCE_DIR}/src/scripts/authorized_keys.sh" \ "${SOURCE_DIR}/src/scripts/node.sh" \ "${SOURCE_DIR}/src/scripts/mvlogrotateconfig.sh" \