zeroclaw-labs/zeroclaw · critical · anyhow::Error
systemctl restart failed: {}
Error message
systemctl restart failed: {} What it means
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.
Source
Thrown at crates/zeroclaw-channels/src/orchestrator/mod.rs:8825
return Ok(false);
}
let active_output = Command::new("systemctl")
.args(SYSTEMD_STATUS_ARGS)
.output()
.context("Failed to query systemd service state")?;
let state = String::from_utf8_lossy(&active_output.stdout);
if !state.trim().eq_ignore_ascii_case("active") {
return Ok(false);
}
let restart_output = Command::new("systemctl")
.args(SYSTEMD_RESTART_ARGS)
.output()
.context("Failed to restart systemd daemon service")?;
if !restart_output.status.success() {
let stderr = String::from_utf8_lossy(&restart_output.stderr);
anyhow::bail!("systemctl restart failed: {}", stderr.trim());
}
return Ok(true);
}
Ok(false)
}
#[cfg(any(
test,
feature = "channel-discord",
feature = "channel-lark",
feature = "channel-matrix",
feature = "channel-slack",
feature = "channel-telegram",
feature = "channel-wechat",
feature = "whatsapp-web",
))]View on GitHub (pinned to 88bb9c8533)
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
Example fix
# before # systemctl restart failed: Failed to start zeroclaw.service: Unit ... # after systemctl --user daemon-reload systemctl --user restart zeroclaw.service journalctl --user -u zeroclaw.service -n 50 # confirm active
Defensive patterns
Strategy: fallback
Validate before calling
let unit = dirs::home_dir().unwrap().join(".config/systemd/user/zeroclaw.service");
if !unit.exists() { return Ok(()); }
let active = Command::new("systemctl").args(["--user", "is-active", "zeroclaw.service"]).output()?;
if !String::from_utf8_lossy(&active.stdout).trim().eq_ignore_ascii_case("active") { return Ok(()); } Try / catch
if let Err(e) = maybe_restart_managed_daemon_service() {
eprintln!("restart failed ({e:#}); run `systemctl --user restart zeroclaw.service`");
// check `journalctl --user -u zeroclaw.service` before retrying
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- rc-service restart failed: {}
- launchctl start failed: {}
- systemd user lingering disabled; user service may stop after
- Could not detect init system. Supported: systemd, OpenRC. Us
- Linux service {action} only manages the default zeroclaw ser
AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23).
Data as JSON: /api/errors/93233132c584e3da.
Report an issue: GitHub.