fix(service): harden OpenRC restart fallback and uninstall resilience

- Linux managed daemon now falls back to systemd when OpenRC restart probe fails, instead of returning early with no action.

- OpenRC uninstall no longer fails hard if rc-update del fails; it warns and continues to remove the init script.
This commit is contained in:
Jakub Buzuk 2026-02-18 16:41:47 +01:00 committed by Chummy
parent 076e9be9e5
commit 71acd1245c
2 changed files with 20 additions and 17 deletions

View File

@ -1921,24 +1921,21 @@ fn maybe_restart_managed_daemon_service() -> Result<bool> {
// OpenRC (system-wide) takes precedence over systemd (user-level)
let openrc_init_script = PathBuf::from("/etc/init.d/zeroclaw");
if openrc_init_script.exists() {
let status_output = Command::new("rc-service")
.args(OPENRC_STATUS_ARGS)
.output()
.context("Failed to query OpenRC service state")?;
// rc-service exits 0 if running, non-zero otherwise
if status_output.status.success() {
let restart_output = Command::new("rc-service")
.args(OPENRC_RESTART_ARGS)
.output()
.context("Failed to restart OpenRC daemon service")?;
if !restart_output.status.success() {
let stderr = String::from_utf8_lossy(&restart_output.stderr);
anyhow::bail!("rc-service restart failed: {}", stderr.trim());
if let Ok(status_output) = Command::new("rc-service").args(OPENRC_STATUS_ARGS).output()
{
// rc-service exits 0 if running, non-zero otherwise
if status_output.status.success() {
let restart_output = Command::new("rc-service")
.args(OPENRC_RESTART_ARGS)
.output()
.context("Failed to restart OpenRC daemon service")?;
if !restart_output.status.success() {
let stderr = String::from_utf8_lossy(&restart_output.stderr);
anyhow::bail!("rc-service restart failed: {}", stderr.trim());
}
return Ok(true);
}
return Ok(true);
}
return Ok(false);
}
// Systemd (user-level)

View File

@ -359,7 +359,13 @@ fn uninstall_linux(config: &Config, init_system: InitSystem) -> Result<()> {
InitSystem::Openrc => {
let init_script = Path::new("/etc/init.d/zeroclaw");
if init_script.exists() {
run_checked(Command::new("rc-update").args(["del", "zeroclaw", "default"]))?;
if let Err(err) =
run_checked(Command::new("rc-update").args(["del", "zeroclaw", "default"]))
{
eprintln!(
"⚠️ Warning: Could not remove zeroclaw from OpenRC default runlevel: {err}"
);
}
fs::remove_file(init_script)
.with_context(|| format!("Failed to remove {}", init_script.display()))?;
}