jdx/mise · error

refusing unsafe change to bootstrap service

Error message

refusing unsafe change to bootstrap service '{}'; current state remains unknown after systemctl daemon-reload

What it means

mise refuses to apply start/stop/enable changes to a bootstrap service when the plan's action is `ResourceAction::Unknown`, i.e. even after `systemctl daemon-reload` the current state of the unit could not be determined. Throwing here prevents blindly running systemctl commands against a unit whose state mise does not know, which could stop or mask a service the user depends on.

Solutions

  1. Re-run the mise command so the unit is re-inspected fresh before a plan is computed
  2. Check `systemctl status <unit>` and `systemctl list-unit-files` to confirm the unit exists and is loadable
  3. Run `systemctl daemon-reload` manually and verify the unit is no longer in a not-found/errored state
  4. If the unit is intentionally gone, remove or fix its bootstrap service declaration in mise.toml

Example fix

// before: applying a plan with unknown action
apply_privileged_plan_from_stdin(plan)?;
// after: verify state before apply
let status = std::process::Command::new("systemctl").args(["status", &unit]).status()?;
assert!(status.success(), "unit {} not inspectable; fix before apply", unit);
apply_privileged_plan_from_stdin(plan)?;
Defensive patterns

Strategy: validation

Validate before calling

systemctl status <unit> >/dev/null && systemctl cat <unit> >/dev/null || echo "unit state unknown; fix before applying bootstrap plan"

Try / catch

match result { Err(e) if e.contains("refusing unsafe change") => re-inspect_and_retry(), Err(e) => return Err(e), Ok(v) => Ok(v) }

Prevention

When it happens

Trigger: `apply_privileged_plan_from_stdin` processes a privileged service plan and calls `commands_after_reload`, but the unit inspection performed earlier yielded no known action (unit not found, systemctl inspect failed, or the unit appeared/disappeared after daemon-reload) so `plan().action` is `ResourceAction::Unknown`.

Common situations: A unit file was hand-edited or removed between inspection and apply; systemd is degraded or the unit is masked; running in a container where systemctl cannot report unit state; daemon-reload invalidated the previously inspected state.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of jdx/mise@533346cc37 (2026-09-17). Data as JSON: /api/errors/bc79d09e685ba6e2. Report an issue: GitHub.

Appendix: source

Thrown at src/system/services.rs:330

        let Some(parent) = path.parent() else {
            return false;
        };
        if !SYSTEM_UNIT_PATHS
            .iter()
            .any(|candidate| parent == *candidate)
        {
            return false;
        }
        path.file_name().is_some_and(|name| {
            name == self.unit.as_str()
                || instantiated_unit_template(&self.unit)
                    .is_some_and(|template| name == template.as_str())
        })
    }

    fn commands_after_reload(&self, notified: bool) -> Result<Vec<Vec<String>>> {
        if self.plan().action == ResourceAction::Unknown {
            bail!(
                "refusing unsafe change to bootstrap service '{}'; current state remains unknown after systemctl daemon-reload",
                self.name
            );
        }
        Ok(self
            .action(ServiceChange {
                notified,
                provides_unit: false,
            })?
            .map(|action| action.commands())
            .unwrap_or_default())
    }
}

const SYSTEM_UNIT_PATHS: &[&str] = &[
    "/etc/systemd/system.control",
    "/run/systemd/system.control",
    "/run/systemd/transient",

View on GitHub (pinned to 533346cc37)