frpc: restart it the first time the admin lines are added (a reload can't work yet)

Found in the VM test: the new install's tunnels never opened, because
frpc only reads admin_addr when it starts, so the first reload failed.
That first time (and whenever a reload fails), frpc is restarted under
systemd and the report says so; later changes reload as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 15:48:28 +02:00
co-authored by Claude Opus 5.5
parent f3f6dc8f7a
commit 19709c2c75
2 changed files with 45 additions and 1 deletions
+21 -1
View File
@@ -94,6 +94,8 @@ frpc_add() {
fi
new="$(mktemp "$(dirname "$FRPC_INI")/.frpc.ini.XXXXXX")"
with_admin_lines "$FRPC_INI" > "$new"
# The admin lines were added just now: the running frpc only reads them when it starts.
grep -q "^admin_addr" "$FRPC_INI" || FRPC_NEEDS_RESTART=1
# Keep the file's last line intact: only add a newline if it had none.
[ -z "$(tail -c 1 "$new")" ] || echo >> "$new"
{ echo; frpc_block "$church" "$product" "$web" "$api"; } >> "$new"
@@ -122,6 +124,24 @@ frpc_remove() {
info "frpc: removed $church-$product."
}
FRPC_NEEDS_RESTART=0
# frpc_reload: picks up the changed frpc.ini. Normally a reload (no other tunnel drops). The first
# time the admin lines were added, or if the reload fails, frpc is restarted instead: its other
# tunnels drop for a few seconds (found in the VM test: a reload can't work before the restart).
frpc_reload() {
"$FRPC_BIN" reload -c "$FRPC_INI" || warn "frpc reload failed: restart frpc (systemctl restart frpc) to pick up the change."
if [ "$FRPC_NEEDS_RESTART" != 1 ] && "$FRPC_BIN" reload -c "$FRPC_INI" >/dev/null 2>&1; then
return 0
fi
if command -v systemctl >/dev/null && systemctl list-unit-files frpc.service >/dev/null 2>&1 && systemctl cat frpc >/dev/null 2>&1; then
if [ "$FRPC_NEEDS_RESTART" = 1 ]; then
warn "frpc: restarting it once so it reads the admin lines (its other tunnels drop for a few seconds; later changes reload without this)."
else
warn "frpc: reload didn't work, so restarting it (its other tunnels drop for a few seconds)."
fi
report_result frpcRestarted true
systemctl restart frpc && FRPC_NEEDS_RESTART=0 && return 0
fi
warn "frpc couldn't be reloaded or restarted: restart it by hand (systemctl restart frpc) to pick up the change."
return 1
}