diff --git a/setup/start/sudoers b/setup/start/sudoers index 8a7f3bd44..30a14f29f 100644 --- a/setup/start/sudoers +++ b/setup/start/sudoers @@ -40,3 +40,6 @@ 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 diff --git a/src/addons.js b/src/addons.js index fa15d404f..fad7035e7 100644 --- a/src/addons.js +++ b/src/addons.js @@ -206,6 +206,11 @@ const KNOWN_SERVICES = { status: statusDocker, restart: restartDocker, defaultMemoryLimit: 0 + }, + unbound: { + status: statusUnbound, + restart: restartUnbound, + defaultMemoryLimit: 0 } }; @@ -1680,3 +1685,19 @@ function restartDocker(callback) { callback(null); } + +function statusUnbound(callback) { + assert.strictEqual(typeof callback, 'function'); + + shell.exec('statusUnbound', 'systemctl is-active unbound', function (error) { + callback(null, { status: error ? exports.ADDON_STATUS_STOPPED : exports.ADDON_STATUS_ACTIVE }); + }); +} + +function restartUnbound(callback) { + assert.strictEqual(typeof callback, 'function'); + + shell.sudo('restartunbound', [ path.join(__dirname, 'scripts/restartunbound.sh') ], {}, NOOP_CALLBACK); + + callback(null); +} diff --git a/src/scripts/restartunbound.sh b/src/scripts/restartunbound.sh new file mode 100755 index 000000000..5aec43b7b --- /dev/null +++ b/src/scripts/restartunbound.sh @@ -0,0 +1,19 @@ +#!/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/test/checkInstall b/src/test/checkInstall index e9651ee52..819382666 100755 --- a/src/test/checkInstall +++ b/src/test/checkInstall @@ -15,6 +15,7 @@ scripts=("${SOURCE_DIR}/src/scripts/rmvolume.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/update.sh" \ "${SOURCE_DIR}/src/scripts/collectlogs.sh" \ "${SOURCE_DIR}/src/scripts/configurecollectd.sh" \