{"record":{"id":"bc79d09e685ba6e2","repo":"jdx/mise","slug":"refusing-unsafe-change-to-bootstrap-service-bc79d0","errorCode":null,"errorMessage":"refusing unsafe change to bootstrap service '{}'; current state remains unknown after systemctl daemon-reload","messagePattern":"refusing unsafe change to bootstrap service '(.+?)'; current state remains unknown after systemctl daemon-reload","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/services.rs","lineNumber":330,"sourceCode":"        let Some(parent) = path.parent() else {\n            return false;\n        };\n        if !SYSTEM_UNIT_PATHS\n            .iter()\n            .any(|candidate| parent == *candidate)\n        {\n            return false;\n        }\n        path.file_name().is_some_and(|name| {\n            name == self.unit.as_str()\n                || instantiated_unit_template(&self.unit)\n                    .is_some_and(|template| name == template.as_str())\n        })\n    }\n\n    fn commands_after_reload(&self, notified: bool) -> Result<Vec<Vec<String>>> {\n        if self.plan().action == ResourceAction::Unknown {\n            bail!(\n                \"refusing unsafe change to bootstrap service '{}'; current state remains unknown after systemctl daemon-reload\",\n                self.name\n            );\n        }\n        Ok(self\n            .action(ServiceChange {\n                notified,\n                provides_unit: false,\n            })?\n            .map(|action| action.commands())\n            .unwrap_or_default())\n    }\n}\n\nconst SYSTEM_UNIT_PATHS: &[&str] = &[\n    \"/etc/systemd/system.control\",\n    \"/run/systemd/system.control\",\n    \"/run/systemd/transient\",","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/src/system/services.rs#L312-L348","documentation":"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.","triggerScenarios":"`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`.","commonSituations":"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.","solutions":["Re-run the mise command so the unit is re-inspected fresh before a plan is computed","Check `systemctl status <unit>` and `systemctl list-unit-files` to confirm the unit exists and is loadable","Run `systemctl daemon-reload` manually and verify the unit is no longer in a not-found/errored state","If the unit is intentionally gone, remove or fix its bootstrap service declaration in mise.toml"],"exampleFix":"// before: applying a plan with unknown action\napply_privileged_plan_from_stdin(plan)?;\n// after: verify state before apply\nlet status = std::process::Command::new(\"systemctl\").args([\"status\", &unit]).status()?;\nassert!(status.success(), \"unit {} not inspectable; fix before apply\", unit);\napply_privileged_plan_from_stdin(plan)?;","handlingStrategy":"validation","validationCode":"systemctl status <unit> >/dev/null && systemctl cat <unit> >/dev/null || echo \"unit state unknown; fix before applying bootstrap plan\"","typeGuard":null,"tryCatchPattern":"match result { Err(e) if e.contains(\"refusing unsafe change\") => re-inspect_and_retry(), Err(e) => return Err(e), Ok(v) => Ok(v) }","preventionTips":["Avoid mutating unit files between inspection and apply","Ensure systemd is healthy (`systemctl is-system-running`) before bootstrap operations","Remove declarations for units that no longer exist"],"tags":["systemd","bootstrap-service","safety-check"],"backgroundTag":"invalid-state-transition","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}