diff --git a/openwisp-config/files/openwisp.agent b/openwisp-config/files/openwisp.agent index 26092fb..dfc9adc 100644 --- a/openwisp-config/files/openwisp.agent +++ b/openwisp-config/files/openwisp.agent @@ -46,6 +46,7 @@ CONFIGURATION_BACKUP="$WORKING_DIR/backup.tar.gz" REGISTRATION_PARAMETERS="$WORKING_DIR/registration_parameters" TEST_CHECKSUM="$WORKING_DIR/test_checksum" STATUS_REPORT="$WORKING_DIR/status_report" +APPLYING_CONF="$WORKING_DIR/applying_conf" REGISTRATION_URL="$URL/controller/register/" DEFAULT_DIR="/etc/openwisp-config-defaults" FETCH_COMMAND="curl -s" @@ -292,12 +293,18 @@ update_configuration() { return 3 fi + # control file to avoid reloading the agent while + # configuration is still being applied + touch $APPLYING_CONF + if [ "$TEST_CONFIG" == "1" ]; then test_configuration $CONFIGURATION_ARCHIVE else apply_configuration $CONFIGURATION_ARCHIVE fi + rm $APPLYING_CONF + if [ "$?" == "0" ]; then logger -s "Configuration applied" \ -t openwisp \ diff --git a/openwisp-config/files/openwisp.init b/openwisp-config/files/openwisp.init index 01e0ea7..b64f879 100644 --- a/openwisp-config/files/openwisp.init +++ b/openwisp-config/files/openwisp.init @@ -65,3 +65,20 @@ stop_service() { -t openwisp \ -p daemon.info } + +reload_service() { + logger -s "$PROG_NAME received reload trigger" \ + -t openwisp \ + -p daemon.info + # avoid reloading while configuration is being applied + # will wait for a maximum of 30 seconds + for i in $(seq 1 30); do + if [ -f "/tmp/openwisp/applying_conf" ]; then + sleep 1 + else + break + fi + done + # reload + start +}