Skip to content

Commit c58683e

Browse files
committed
[fix] Delay stop until configuration is applied #172
Extends the protection already in place for reload_service to stop_service as well. Extracted the 30-second wait loop into a reusable wait_applying_config() helper function to avoid code duplication. Closes #172
1 parent 4549659 commit c58683e

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

openwisp-config/files/openwisp.init

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,21 +82,27 @@ service_triggers() {
8282
procd_add_reload_trigger openwisp
8383
}
8484

85-
stop_service() {
86-
logger -s "$PROG_NAME stopping" -t openwisp -p daemon.info
87-
}
88-
89-
reload_service() {
90-
logger -s "$PROG_NAME received reload trigger" -t openwisp -p daemon.info
91-
# avoid reloading while configuration is being applied
85+
wait_applying_config() {
86+
# avoid stopping/reloading while configuration is being applied
9287
# will wait for a maximum of 30 seconds
9388
for _ in $(seq 1 30); do
9489
if [ -f "$CONTROL_FILE" ]; then
9590
sleep 1
9691
else
97-
break
92+
return 0
9893
fi
9994
done
95+
# timed out: remove stale marker so we can proceed
10096
rm -f "$CONTROL_FILE"
97+
}
98+
99+
stop_service() {
100+
logger -s "$PROG_NAME stopping" -t openwisp -p daemon.info
101+
wait_applying_config
102+
}
103+
104+
reload_service() {
105+
logger -s "$PROG_NAME received reload trigger" -t openwisp -p daemon.info
106+
wait_applying_config
101107
start
102108
}

0 commit comments

Comments
 (0)