jdx/mise · error

systemctl {} failed: {}

Error message

systemctl {} failed: {}

What it means

Every systemctl invocation mise makes while applying bootstrap services goes through `run_systemctl`; when systemctl exits non-zero, mise surfaces the joined command and the captured stderr/stdout of the failure. This is a wrapper error: the underlying cause is whatever systemd reported for that specific subcommand (start, stop, enable, disable, mask, unmask, daemon-reload).

Source

Thrown at src/system/services.rs:714

        active_state: properties
            .get("ActiveState")
            .copied()
            .unwrap_or("unknown")
            .to_string(),
        unit_file_state: properties
            .get("UnitFileState")
            .copied()
            .unwrap_or("unknown")
            .to_string(),
        need_daemon_reload: properties.get("NeedDaemonReload") == Some(&"yes"),
    }
}

fn run_systemctl(systemctl: &std::path::Path, args: &[String]) -> Result<()> {
    info!("$ {} {}", systemctl.display(), shell_words::join(args));
    let output = systemctl_output(systemctl, args)?;
    if !output.status.success() {
        bail!(
            "systemctl {} failed: {}",
            shell_words::join(args),
            output_error(&output)
        );
    }
    Ok(())
}

fn systemctl_output(systemctl: &std::path::Path, args: &[String]) -> Result<Output> {
    Ok(Command::new(systemctl)
        .args(args)
        .env("LC_ALL", "C")
        .env("SYSTEMD_PAGER", "")
        .output()?)
}

fn output_error(output: &Output) -> String {
    let stderr = String::from_utf8_lossy(&output.stderr).trim().to_string();

View on GitHub (pinned to 6f52dcdf99)

Solutions

  1. Re-run the exact `$ systemctl ...` line shown in the error output to reproduce the real failure
  2. Check unit health: `systemctl status <unit>`, `journalctl -xeu <unit>`
  3. Validate the unit file: `systemd-analyze verify /etc/systemd/system/<unit>` and fix reported directives
  4. Ensure privileges: run apply as root or with sudo/polkit authorization
  5. If systemd is not PID 1 (container), enable systemd or run outside such environments

Example fix

$ systemd-analyze verify /etc/systemd/system/myapp.service
# before: ExecStart points to a missing binary -> start fails
ExecStart=/usr/local/bin/myapp-old
# after
ExecStart=/usr/local/bin/myapp
Defensive patterns

Strategy: try-catch

Validate before calling

command -v systemctl >/dev/null && [ -d /run/systemd/system ] && echo systemd-active || echo no-systemd

Try / catch

if ! mise bootstrap apply 2>err.log; then grep -m1 'systemctl .* failed' err.log && systemctl status "$unit"; fi
# surface the exact systemctl subcommand and re-run it manually for the real cause

Prevention

When it happens

Trigger: `mise bootstrap apply` (or plan/apply via the elevated helper) runs e.g. `systemctl enable <unit>`, `systemctl restart <unit>`, or `systemctl daemon-reload` and the command exits non-zero — invalid unit file, unit not loaded, masked unit, polkit denial, or systemd not running as init.

Common situations: Unit file with syntax errors so daemon-reload or start fails; attempting to start a masked unit; running without root/polkit rights so enable/start is denied; systemd inactive in containers; unit referenced but its dependency (user, binary, ExecStart path) missing so start fails immediately.

Related errors


AI-assisted analysis of jdx/mise@6f52dcdf99 (2026-08-22). Data as JSON: /api/errors/a85bd77d6de33fd5. Report an issue: GitHub.