[control] Fix round 2: Caddy rereads its files on every load and the served certificate is checked, Caddy trials get a deadline outside control (caddy-guard, caddy-revert), the watch under Caddy judges upstreams as edge does, a reload of Caddy during the watch is noticed and device changes wait for the apply, stricter root key scan, IPv4-mapped trusted proxies

This commit is contained in:
2026-11-08 12:04:13 +01:00
parent ba3a060b2e
commit 23a283ece9
12 changed files with 884 additions and 159 deletions
+16 -5
View File
@@ -230,9 +230,17 @@ case "$1:$2" in
start:caddy-fallback.service)
XDG_DATA_HOME="{d}/caddy-state" XDG_CONFIG_HOME="{d}/caddy-state" HOME="{d}/caddy-state" \
nohup "{c}" run --config "{d}/caddy/caddy.json" >> "{d}/logs/caddy.log" 2>&1 &
echo $! > "{d}/fake/caddy.pid"; touch "$dir/$2" ;;
echo $! > "{d}/fake/caddy.pid"
# The NixOS module starts ianitor-caddy-guard with caddy-fallback (crate::caddy_guard).
if [ ! -e "{d}/fake/no-guard" ]; then
IANITOR_LOG=info nohup "{g}" caddy-guard --config "{d}/control.toml" >> "{d}/logs/caddy-guard.log" 2>&1 &
echo $! > "{d}/fake/guard.pid"
fi
touch "$dir/$2" ;;
stop:caddy-fallback.service)
[ -f "{d}/fake/caddy.pid" ] && kill "$(cat "{d}/fake/caddy.pid")" 2>/dev/null; rm -f "$dir/$2" "{d}/fake/caddy.pid" ;;
[ -f "{d}/fake/caddy.pid" ] && kill "$(cat "{d}/fake/caddy.pid")" 2>/dev/null
[ -f "{d}/fake/guard.pid" ] && kill "$(cat "{d}/fake/guard.pid")" 2>/dev/null
rm -f "$dir/$2" "{d}/fake/caddy.pid" "{d}/fake/guard.pid" ;;
start:*) touch "$dir/$2" ;;
stop:*) rm -f "$dir/$2" ;;
is-active:*) [ "$2" = "--quiet" ] && shift; [ -e "$dir/$2" ] ;;
@@ -240,7 +248,8 @@ case "$1:$2" in
esac
"#,
d = dir.display(),
c = caddy.display()
c = caddy.display(),
g = env!("CARGO_BIN_EXE_ianitor-control"),
)
}
@@ -251,8 +260,10 @@ esac
impl Drop for CaddyEnv {
fn drop(&mut self) {
if let Ok(p) = std::fs::read_to_string(self.env.dir.join("fake/caddy.pid")) {
let _ = std::process::Command::new("kill").arg(p.trim()).status();
for f in ["fake/caddy.pid", "fake/guard.pid"] {
if let Ok(p) = std::fs::read_to_string(self.env.dir.join(f)) {
let _ = std::process::Command::new("kill").arg(p.trim()).status();
}
}
}
}