{"record":{"id":"93233132c584e3da","repo":"zeroclaw-labs/zeroclaw","slug":"systemctl-restart-failed","errorCode":null,"errorMessage":"systemctl restart failed: {}","messagePattern":"systemctl restart failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"crates/zeroclaw-channels/src/orchestrator/mod.rs","lineNumber":8825,"sourceCode":"            return Ok(false);\n        }\n\n        let active_output = Command::new(\"systemctl\")\n            .args(SYSTEMD_STATUS_ARGS)\n            .output()\n            .context(\"Failed to query systemd service state\")?;\n        let state = String::from_utf8_lossy(&active_output.stdout);\n        if !state.trim().eq_ignore_ascii_case(\"active\") {\n            return Ok(false);\n        }\n\n        let restart_output = Command::new(\"systemctl\")\n            .args(SYSTEMD_RESTART_ARGS)\n            .output()\n            .context(\"Failed to restart systemd daemon service\")?;\n        if !restart_output.status.success() {\n            let stderr = String::from_utf8_lossy(&restart_output.stderr);\n            anyhow::bail!(\"systemctl restart failed: {}\", stderr.trim());\n        }\n\n        return Ok(true);\n    }\n\n    Ok(false)\n}\n\n#[cfg(any(\n    test,\n    feature = \"channel-discord\",\n    feature = \"channel-lark\",\n    feature = \"channel-matrix\",\n    feature = \"channel-slack\",\n    feature = \"channel-telegram\",\n    feature = \"channel-wechat\",\n    feature = \"whatsapp-web\",\n))]","sourceCodeStart":8807,"sourceCodeEnd":8843,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-channels/src/orchestrator/mod.rs#L8807-L8843","documentation":"Thrown by maybe_restart_managed_daemon_service on Linux when a user-level systemd unit exists (~/.config/systemd/user/zeroclaw.service), `systemctl --user is-active` (SYSTEMD_STATUS_ARGS) reported `active`, and the subsequent `systemctl --user restart zeroclaw.service` (SYSTEMD_RESTART_ARGS) exits non-zero. Because the unit was active before, a failed restart usually leaves it inactive — check and restore it promptly.","triggerScenarios":"Any config-save path that auto-reloads the daemon (e.g. allowlist bind save) on a systemd desktop/server host where the user unit is active. Common failure sources: the unit's ExecStart path is stale after reinstall, the new config crashes the binary on start, or the user systemd session (DBUS/XDG_RUNTIME_DIR) is unavailable from the invoking context (cron, ssh without lingering).","commonSituations":"Binary reinstalled to a different path while ~/.config/systemd/user/zeroclaw.service kept the old ExecStart; running over SSH/cron where the user manager is not reachable; daemon exits at boot due to invalid config edited just before the restart; `loginctl enable-linger` missing so the user bus disappears.","solutions":["Restore immediately: `systemctl --user restart zeroclaw.service` and run `journalctl --user -u zeroclaw.service -n 50` for the exact startup error","If ExecStart is stale, re-run the service install (e.g. `zeroclaw service install`) or edit ~/.config/systemd/user/zeroclaw.service to the current binary path, then `systemctl --user daemon-reload`","Fix the underlying config error if the daemon crashes on the new config; validate with a foreground run first","For headless/cron contexts, ensure `loginctl enable-linger <user>` and XDG_RUNTIME_DIR are set so the user manager is reachable"],"exampleFix":"# before\n# systemctl restart failed: Failed to start zeroclaw.service: Unit ... \n\n# after\nsystemctl --user daemon-reload\nsystemctl --user restart zeroclaw.service\njournalctl --user -u zeroclaw.service -n 50   # confirm active","handlingStrategy":"fallback","validationCode":"let unit = dirs::home_dir().unwrap().join(\".config/systemd/user/zeroclaw.service\");\nif !unit.exists() { return Ok(()); }\nlet active = Command::new(\"systemctl\").args([\"--user\", \"is-active\", \"zeroclaw.service\"]).output()?;\nif !String::from_utf8_lossy(&active.stdout).trim().eq_ignore_ascii_case(\"active\") { return Ok(()); }","typeGuard":null,"tryCatchPattern":"if let Err(e) = maybe_restart_managed_daemon_service() {\n    eprintln!(\"restart failed ({e:#}); run `systemctl --user restart zeroclaw.service`\");\n    // check `journalctl --user -u zeroclaw.service` before retrying\n}","preventionTips":["Run `systemctl --user daemon-reload` after changing the unit or binary path","Enable `loginctl enable-linger` on headless hosts so the user manager survives logout","Foreground-test new configs before any flow that auto-restarts the unit"],"tags":["daemon","systemd","linux","service-restart","zeroclaw"],"backgroundTag":"service-start-failure","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}