Skip to content

Commit 8550d35

Browse files
[feature] Added SIGUSR2 support to force config reload #181
Closes #181 --------- Co-authored-by: Federico Capoano <f.capoano@openwisp.io>
1 parent e51e6d8 commit 8550d35

2 files changed

Lines changed: 53 additions & 1 deletion

File tree

docs/user/debugging.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,32 @@ You can inspect the version of openwisp-config currently installed with:
3131
.. code-block:: shell
3232
3333
openwisp-config --version
34+
35+
Forcing Configuration Update
36+
----------------------------
37+
38+
You can force openwisp-config to immediately download and apply the latest
39+
configuration from the controller using the ``--force-update`` option:
40+
41+
.. code-block:: shell
42+
43+
openwisp-config --force-update
44+
45+
This command checks if the openwisp-config agent is running and sends a
46+
SIGUSR2 signal to trigger an immediate configuration update. If the agent
47+
is not running, the command will exit with an error.
48+
49+
Alternatively, you can manually send the SIGUSR2 signal to the agent
50+
process:
51+
52+
.. code-block:: shell
53+
54+
kill -USR2 "$(pgrep -P 1 -f openwisp-config)"
55+
56+
This is useful when you need to:
57+
58+
- Force the device to fetch the latest configuration without waiting for
59+
the next polling interval
60+
- Apply configuration changes immediately after making updates in OpenWISP
61+
Controller
62+
- Troubleshoot configuration synchronization issues

openwisp-config/files/openwisp.agent

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,17 @@ while [ -n "$1" ]; do
99
export VERSION=1
1010
break
1111
;;
12+
--force-update)
13+
# Check if agent is running and send SIGUSR2 to force configuration reload
14+
AGENT_PID=$(pgrep -P 1 -f openwisp-config)
15+
if [ -z "$AGENT_PID" ]; then
16+
echo "Error: openwisp-config agent is not running" >&2
17+
exit 1
18+
fi
19+
kill -USR2 "$AGENT_PID"
20+
echo "Sent SIGUSR2 to openwisp-config agent (PID: $AGENT_PID) to force configuration update"
21+
exit 0
22+
;;
1223
--url)
1324
export URL="${2%/}"
1425
shift
@@ -915,6 +926,15 @@ handle_sigusr1() {
915926
-p daemon.info
916927
}
917928

929+
handle_sigusr2() {
930+
logger -s "Received SIGUSR2: forcing configuration update..." \
931+
-t openwisp \
932+
-p daemon.info
933+
# Remove checksum files to ensure configuration_changed returns 1
934+
# which will trigger update_configuration on the next loop iteration
935+
rm -f "$CONFIGURATION_CHECKSUM" "$PERSISTENT_CHECKSUM"
936+
}
937+
918938
# ensure both UUID and KEY are defined
919939
# otherwise perform registration
920940
if [ -z "$UUID" ] || [ -z "$KEY" ]; then
@@ -972,8 +992,11 @@ while true; do
972992

973993
# handle SIGUSR1 to interrupt sleep
974994
trap handle_sigusr1 USR1
995+
# handle SIGUSR2 to force downloading and applying config again
996+
trap handle_sigusr2 USR2
975997
sleep "$INTERVAL" &
976998
wait $!
977-
# ignore SIGUSR1 signals again
999+
# ignore SIGUSR1 and SIGUSR2 signals again
9781000
trap "" USR1
1001+
trap "" USR2
9791002
done

0 commit comments

Comments
 (0)