Description
When the gateway is running under systemd and a config change triggers a restart (via SIGUSR1 hot-reload), the gateway spawns a new process that is NOT managed by systemd. This creates an "orphan" process that blocks subsequent systemd restart attempts.
Detected during debugging session with Claude Code
Environment
- OpenClaw version: 2026.2.1
- OS: Ubuntu Linux (systemd user service)
- Node: 22.x
Steps to Reproduce
- Run gateway via systemd:
systemctl --user start openclaw-gateway
- Change a config value that requires restart (e.g.,
agents.defaults.model.primary)
- Gateway detects change, sends SIGUSR1 for hot-reload
- A NEW process spawns outside systemd's control
- Systemd tries to restart but fails because orphan holds port 18789
- Results in restart storm (29 failed attempts in my case)
Expected Behavior
When running under systemd (detected via OPENCLAW_SYSTEMD_UNIT env var), config changes requiring restart should either:
- Use
systemctl --user restart openclaw-gateway instead of spawning directly
- Or do a true in-process restart without forking new PIDs
Actual Behavior
Gateway spawns new process via CLI invocation (with --force flag), creating orphan that blocks systemd-managed restarts.
Logs
17:55:16 [reload] config change requires gateway restart (meta.lastTouchedAt)
17:55:16 [gateway] signal SIGUSR1 received
17:55:42 [gateway] signal SIGTERM received
17:55:57 [gateway] listening on ws://127.0.0.1:18789 (PID 334259) # NEW orphan PID!
17:56:08 [gateway] force: killed pid 334259 (openclaw-gatewa) on port 18789
17:56:08 [gateway] listening on ws://127.0.0.1:18789 (PID 334429) # Another orphan!
17:56:16+ systemd: Failed with result 'exit-code' (29 times)
Workaround
Kill orphan processes and restart via systemd:
pkill -f openclaw-gateway && systemctl --user start openclaw-gateway
Suggested Fix
In the hot-reload code, detect if running under systemd:
if (process.env.OPENCLAW_SYSTEMD_UNIT) {
// Use systemd to restart instead of spawning directly
execSync('systemctl --user restart ' + process.env.OPENCLAW_SYSTEMD_UNIT);
} else {
// Current behavior for non-systemd environments
}
Description
When the gateway is running under systemd and a config change triggers a restart (via SIGUSR1 hot-reload), the gateway spawns a new process that is NOT managed by systemd. This creates an "orphan" process that blocks subsequent systemd restart attempts.
Detected during debugging session with Claude Code
Environment
Steps to Reproduce
systemctl --user start openclaw-gatewayagents.defaults.model.primary)Expected Behavior
When running under systemd (detected via
OPENCLAW_SYSTEMD_UNITenv var), config changes requiring restart should either:systemctl --user restart openclaw-gatewayinstead of spawning directlyActual Behavior
Gateway spawns new process via CLI invocation (with
--forceflag), creating orphan that blocks systemd-managed restarts.Logs
Workaround
Kill orphan processes and restart via systemd:
pkill -f openclaw-gateway && systemctl --user start openclaw-gatewaySuggested Fix
In the hot-reload code, detect if running under systemd: