diff --git a/setup/start/sudoers b/setup/start/sudoers index 7bdd4d454..f5f1f4eac 100644 --- a/setup/start/sudoers +++ b/setup/start/sudoers @@ -13,9 +13,6 @@ yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/mkdirvolume.sh Defaults!/home/yellowtent/box/src/scripts/rmaddondir.sh env_keep="HOME BOX_ENV" yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/rmaddondir.sh -Defaults!/home/yellowtent/box/src/scripts/reloadnginx.sh env_keep="HOME BOX_ENV" -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 @@ -41,11 +38,8 @@ yellowtent ALL=(root) NOPASSWD:SETENV: /home/yellowtent/box/src/scripts/backupup Defaults!/home/yellowtent/box/src/scripts/restart.sh env_keep="HOME BOX_ENV" yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/restart.sh -Defaults!/home/yellowtent/box/src/scripts/restartdocker.sh env_keep="HOME BOX_ENV" -yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/restartdocker.sh - -Defaults!/home/yellowtent/box/src/scripts/restartunbound.sh env_keep="HOME BOX_ENV" -yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/restartunbound.sh +Defaults!/home/yellowtent/box/src/scripts/restartservice.sh env_keep="HOME BOX_ENV" +yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/restartservice.sh Defaults!/home/yellowtent/box/src/scripts/rmmailbox.sh env_keep="HOME BOX_ENV" yellowtent ALL=(root) NOPASSWD: /home/yellowtent/box/src/scripts/rmmailbox.sh diff --git a/src/reverseproxy.js b/src/reverseproxy.js index 15b369255..bd05fd471 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -54,8 +54,8 @@ var acme2 = require('./cert/acme2.js'), users = require('./users.js'), util = require('util'); -var NGINX_APPCONFIG_EJS = fs.readFileSync(__dirname + '/nginxconfig.ejs', { encoding: 'utf8' }), - RELOAD_NGINX_CMD = path.join(__dirname, 'scripts/reloadnginx.sh'); +const NGINX_APPCONFIG_EJS = fs.readFileSync(__dirname + '/nginxconfig.ejs', { encoding: 'utf8' }); +const RESTART_SERVICE_CMD = path.join(__dirname, 'scripts/restartservice.sh'); function nginxLocation(s) { if (!s.startsWith('!')) return s; @@ -172,7 +172,7 @@ function validateCertificate(location, domainObject, certificate) { function reload(callback) { if (constants.TEST) return callback(); - shell.sudo('reload', [ RELOAD_NGINX_CMD ], {}, function (error) { + shell.sudo('reload', [ RESTART_SERVICE_CMD, 'nginx' ], {}, function (error) { if (error) return callback(new BoxError(BoxError.NGINX_ERROR, `Error reloading nginx: ${error.message}`)); callback(); diff --git a/src/scripts/reloadnginx.sh b/src/scripts/reloadnginx.sh deleted file mode 100755 index 6eb9c47f0..000000000 --- a/src/scripts/reloadnginx.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/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 - -if [[ "${BOX_ENV}" == "cloudron" ]]; then - nginx -s reload -fi diff --git a/src/scripts/restartdocker.sh b/src/scripts/restartdocker.sh deleted file mode 100755 index 951e88d91..000000000 --- a/src/scripts/restartdocker.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/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 - -if [[ "${BOX_ENV}" == "cloudron" ]]; then - systemctl restart docker -fi - diff --git a/src/scripts/restartservice.sh b/src/scripts/restartservice.sh new file mode 100755 index 000000000..1a3fd4d63 --- /dev/null +++ b/src/scripts/restartservice.sh @@ -0,0 +1,37 @@ +#!/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 [[ $# -eq 0 ]]; then + echo "No arguments supplied" + exit 1 +fi + +if [[ "$1" == "--check" ]]; then + echo "OK" + exit 0 +fi + +[[ "${BOX_ENV}" != "cloudron" ]] && exit + +service="$1" + +if [[ "${service}" == "unbound" ]]; then + unbound-anchor -a /var/lib/unbound/root.key + systemctl restart unbound +elif [[ "${service}" == "nginx" ]]; then + nginx -s reload +elif [[ "${service}" == "docker" ]]; then + systemctl restart docker +elif [[ "${service}" == "collectd" ]]; then + systemctl restart collectd +else + echo "Unknown service ${service}" + exit 1 +fi + diff --git a/src/scripts/restartunbound.sh b/src/scripts/restartunbound.sh deleted file mode 100755 index 5aec43b7b..000000000 --- a/src/scripts/restartunbound.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/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 - -if [[ "${BOX_ENV}" == "cloudron" ]]; then - unbound-anchor -a /var/lib/unbound/root.key - systemctl restart unbound -fi - diff --git a/src/services.js b/src/services.js index 647a70132..dadf91beb 100644 --- a/src/services.js +++ b/src/services.js @@ -63,6 +63,7 @@ var appdb = require('./appdb.js'), const NOOP = function (app, options, callback) { return callback(); }; const NOOP_CALLBACK = function (error) { if (error) debug(error); }; const RMADDONDIR_CMD = path.join(__dirname, 'scripts/rmaddondir.sh'); +const RESTART_SERVICE_CMD = path.join(__dirname, 'scripts/restartservice.sh'); // setup can be called multiple times for the same app (configure crash restart) and existing data must not be lost // teardown is destructive. app data stored with the addon is lost @@ -218,7 +219,7 @@ const SERVICES = { }, graphite: { status: statusGraphite, - restart: docker.restartContainer.bind(null, 'graphite'), + restart: restartGraphite, defaultMemoryLimit: 256 * 1024 * 1024 }, nginx: { @@ -2066,7 +2067,7 @@ function statusDocker(callback) { function restartDocker(callback) { assert.strictEqual(typeof callback, 'function'); - shell.sudo('restartdocker', [ path.join(__dirname, 'scripts/restartdocker.sh') ], {}, NOOP_CALLBACK); + shell.sudo('restartdocker', [ RESTART_SERVICE_CMD, 'docker' ], {}, NOOP_CALLBACK); callback(null); } @@ -2082,7 +2083,7 @@ function statusUnbound(callback) { function restartUnbound(callback) { assert.strictEqual(typeof callback, 'function'); - shell.sudo('restartunbound', [ path.join(__dirname, 'scripts/restartunbound.sh') ], {}, NOOP_CALLBACK); + shell.sudo('restartunbound', [ RESTART_SERVICE_CMD, 'unbound' ], {}, NOOP_CALLBACK); callback(null); } @@ -2098,7 +2099,7 @@ function statusNginx(callback) { function restartNginx(callback) { assert.strictEqual(typeof callback, 'function'); - shell.sudo('reloadnginx', [ path.join(__dirname, 'scripts/reloadnginx.sh') ], {}, NOOP_CALLBACK); + shell.sudo('restartnginx', [ RESTART_SERVICE_CMD, 'nginx' ], {}, NOOP_CALLBACK); callback(null); } @@ -2150,6 +2151,17 @@ function statusGraphite(callback) { }); } +function restartGraphite(callback) { + assert.strictEqual(typeof callback, 'function'); + + docker.restartContainer('graphite', callback); + + setTimeout(function () { + // wait for graphite to startup and then restart collectd + shell.sudo('restartcollectd', [ RESTART_SERVICE_CMD, 'collectd' ], {}, NOOP_CALLBACK); + }, 10000); +} + function teardownOauth(app, options, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof options, 'object'); diff --git a/src/test/checkInstall b/src/test/checkInstall index 79b45bae3..2a58ac5ce 100755 --- a/src/test/checkInstall +++ b/src/test/checkInstall @@ -13,11 +13,9 @@ scripts=("${SOURCE_DIR}/src/scripts/clearvolume.sh" \ "${SOURCE_DIR}/src/scripts/mvvolume.sh" \ "${SOURCE_DIR}/src/scripts/mkdirvolume.sh" \ "${SOURCE_DIR}/src/scripts/rmaddondir.sh" \ - "${SOURCE_DIR}/src/scripts/reloadnginx.sh" \ "${SOURCE_DIR}/src/scripts/reboot.sh" \ "${SOURCE_DIR}/src/scripts/restart.sh" \ - "${SOURCE_DIR}/src/scripts/restartdocker.sh" \ - "${SOURCE_DIR}/src/scripts/restartunbound.sh" \ + "${SOURCE_DIR}/src/scripts/restartservice.sh" \ "${SOURCE_DIR}/src/scripts/update.sh" \ "${SOURCE_DIR}/src/scripts/collectlogs.sh" \ "${SOURCE_DIR}/src/scripts/configurecollectd.sh" \ diff --git a/src/test/shell-test.js b/src/test/shell-test.js index 8990a165d..5b0cb87be 100644 --- a/src/test/shell-test.js +++ b/src/test/shell-test.js @@ -39,8 +39,8 @@ describe('shell', function () { }); it('can sudo valid program', function (done) { - var RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/reloadnginx.sh'); - shell.sudo('test', [ RELOAD_NGINX_CMD ], {}, function (error) { + var RELOAD_NGINX_CMD = path.join(__dirname, '../src/scripts/restartservice.sh'); + shell.sudo('test', [ RELOAD_NGINX_CMD, 'nginx' ], {}, function (error) { expect(error).to.be.ok(); done(); });