diff --git a/docs/user/debugging.rst b/docs/user/debugging.rst index 7c6b771..f4742ea 100644 --- a/docs/user/debugging.rst +++ b/docs/user/debugging.rst @@ -31,3 +31,32 @@ You can inspect the version of openwisp-config currently installed with: .. code-block:: shell openwisp-config --version + +Forcing Configuration Update +---------------------------- + +You can force openwisp-config to immediately download and apply the latest +configuration from the controller using the ``--force-update`` option: + +.. code-block:: shell + + openwisp-config --force-update + +This command checks if the openwisp-config agent is running and sends a +SIGUSR2 signal to trigger an immediate configuration update. If the agent +is not running, the command will exit with an error. + +Alternatively, you can manually send the SIGUSR2 signal to the agent +process: + +.. code-block:: shell + + kill -USR2 "$(pgrep -P 1 -f openwisp-config)" + +This is useful when you need to: + +- Force the device to fetch the latest configuration without waiting for + the next polling interval +- Apply configuration changes immediately after making updates in OpenWISP + Controller +- Troubleshoot configuration synchronization issues diff --git a/openwisp-config/files/openwisp.agent b/openwisp-config/files/openwisp.agent index 797e63e..01a4ab9 100755 --- a/openwisp-config/files/openwisp.agent +++ b/openwisp-config/files/openwisp.agent @@ -9,6 +9,17 @@ while [ -n "$1" ]; do export VERSION=1 break ;; + --force-update) + # Check if agent is running and send SIGUSR2 to force configuration reload + AGENT_PID=$(pgrep -P 1 -f openwisp-config) + if [ -z "$AGENT_PID" ]; then + echo "Error: openwisp-config agent is not running" >&2 + exit 1 + fi + kill -USR2 "$AGENT_PID" + echo "Sent SIGUSR2 to openwisp-config agent (PID: $AGENT_PID) to force configuration update" + exit 0 + ;; --url) export URL="${2%/}" shift @@ -915,6 +926,15 @@ handle_sigusr1() { -p daemon.info } +handle_sigusr2() { + logger -s "Received SIGUSR2: forcing configuration update..." \ + -t openwisp \ + -p daemon.info + # Remove checksum files to ensure configuration_changed returns 1 + # which will trigger update_configuration on the next loop iteration + rm -f "$CONFIGURATION_CHECKSUM" "$PERSISTENT_CHECKSUM" +} + # ensure both UUID and KEY are defined # otherwise perform registration if [ -z "$UUID" ] || [ -z "$KEY" ]; then @@ -972,8 +992,11 @@ while true; do # handle SIGUSR1 to interrupt sleep trap handle_sigusr1 USR1 + # handle SIGUSR2 to force downloading and applying config again + trap handle_sigusr2 USR2 sleep "$INTERVAL" & wait $! - # ignore SIGUSR1 signals again + # ignore SIGUSR1 and SIGUSR2 signals again trap "" USR1 + trap "" USR2 done