diff --git a/lxc/var/www/wirecon/cgi-bin/config-save.sh b/lxc/var/www/wirecon/cgi-bin/config-save.sh index 6f2154c..893d5c4 100755 --- a/lxc/var/www/wirecon/cgi-bin/config-save.sh +++ b/lxc/var/www/wirecon/cgi-bin/config-save.sh @@ -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)" +echo "" +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." -for svc in "${restart[@]}"; do - echo "" - echo "--- restart $svc ---" - rc-service "$svc" restart 2>&1 || echo "(restart of $svc returned non-zero)" -done +{ + 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" +} >/var/log/wirecon-restart.log 2>&1 & +disown || true +exit 0 diff --git a/lxc/var/www/wirecon/cgi-bin/logs.sh b/lxc/var/www/wirecon/cgi-bin/logs.sh index b5d5261..566b01f 100755 --- a/lxc/var/www/wirecon/cgi-bin/logs.sh +++ b/lxc/var/www/wirecon/cgi-bin/logs.sh @@ -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"