detach service restarts from config-save CGI
Saving wg0.conf via the web UI restarts wg-quick + watchdog + monitor serially. wg-quick's down/up can take long enough that busybox httpd closes the HTTP socket first, which the browser reports as "Failed to fetch" even though the file was saved. Move the restart loop into a detached background process, log its output to /var/log/wirecon-restart.log (with per-service timeout 20s), and have the CGI return the save confirmation immediately. The new log is also servable via logs.sh?service=restart. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
1 parent
4cb36b7807
commit
e9256e6389
2 files changed
+24
-6
No files matched your search
@@ -51,12 +51,29 @@ chmod "$mode" "$tmp"
|
||||
mv -f "$tmp" "$file"
|
||||
trap - EXIT
|
||||
|
||||
# Restart dependents, collect output for the UI.
|
||||
# Return the save confirmation and kick off restarts in the background so
|
||||
# the HTTP response doesn't depend on wg-quick / watchdog finishing. Their
|
||||
# output is appended to /var/log/wirecon-restart.log (viewable in Logs tab
|
||||
# or via tail -F).
|
||||
printf 'Content-Type: text/plain\r\n\r\n'
|
||||
echo "saved $file ($(wc -c < "$file") bytes)"
|
||||
|
||||
for svc in "${restart[@]}"; do
|
||||
echo ""
|
||||
echo "--- restart $svc ---"
|
||||
rc-service "$svc" restart 2>&1 || echo "(restart of $svc returned non-zero)"
|
||||
echo "restarting in background:"
|
||||
for svc in "${restart[@]}"; do echo " - $svc"; done
|
||||
echo ""
|
||||
echo "watch: tail -F /var/log/wirecon-restart.log"
|
||||
echo "or refresh the Status tab in a few seconds."
|
||||
|
||||
{
|
||||
ts() { date '+%Y-%m-%dT%H:%M:%S%z'; }
|
||||
echo "[$(ts)] config-save: $label ($(wc -c < "$file") bytes) → restarting ${restart[*]}"
|
||||
for svc in "${restart[@]}"; do
|
||||
echo "[$(ts)] --- restart $svc ---"
|
||||
if ! timeout 20 rc-service "$svc" restart 2>&1; then
|
||||
echo "[$(ts)] (restart of $svc returned non-zero or timed out)"
|
||||
fi
|
||||
done
|
||||
echo "[$(ts)] config-save: done"
|
||||
} </dev/null >>/var/log/wirecon-restart.log 2>&1 &
|
||||
disown || true
|
||||
exit 0
|
||||
@@ -7,6 +7,7 @@ service=""; lines=100
|
||||
case "${QUERY_STRING:-}" in
|
||||
*service=watchdog*) service=watchdog ;;
|
||||
*service=monitor*) service=monitor ;;
|
||||
*service=restart*) service=restart ;;
|
||||
esac
|
||||
|
||||
# pull lines= from query string
|
||||
@@ -17,7 +18,7 @@ fi
|
||||
|
||||
if [[ -z "$service" ]]; then
|
||||
printf 'Status: 400 Bad Request\r\nContent-Type: text/plain\r\n\r\n'
|
||||
echo "service must be watchdog or monitor"; exit 0
|
||||
echo "service must be watchdog, monitor, or restart"; exit 0
|
||||
fi
|
||||
|
||||
file="/var/log/wirecon-${service}.log"
|
||||
|
||||
Reference in new issue
Block a user