{"record":{"id":"b771d865f48fa021","repo":"jdx/mise","slug":"systemctl-user-failed","errorCode":null,"errorMessage":"`systemctl --user {}` failed: {}","messagePattern":"`systemctl --user (.+?)` failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/system/systemd.rs","lineNumber":866,"sourceCode":"        );\n    }\n    Ok(false)\n}\n\nasync fn systemctl(args: &[String]) -> Result<()> {\n    debug!(\"$ systemctl --user {}\", shell_words::join(args));\n    let mut cmd = tokio::process::Command::new(\"systemctl\");\n    cmd.arg(\"--user\")\n        .args(args)\n        .stdin(Stdio::null())\n        .stdout(Stdio::piped())\n        .stderr(Stdio::piped())\n        .kill_on_drop(true);\n    let output = tokio::time::timeout(SYSTEMCTL_TIMEOUT, cmd.output())\n        .await\n        .map_err(|_| eyre!(\"`systemctl --user {}` timed out\", shell_words::join(args)))??;\n    if !output.status.success() {\n        bail!(\n            \"`systemctl --user {}` failed: {}\",\n            shell_words::join(args),\n            String::from_utf8_lossy(&output.stderr).trim()\n        );\n    }\n    Ok(())\n}\n\nasync fn disable_unit(unit: &str) -> Result<()> {\n    match systemctl(&[\"disable\".to_string(), unit.to_string()]).await {\n        Ok(()) => Ok(()),\n        Err(err) if disable_unit_error_is_noop(&err.to_string()) => {\n            debug!(\"systemd: ignoring disable for {unit}: {err}\");\n            Ok(())\n        }\n        Err(err) => Err(err),\n    }\n}","sourceCodeStart":848,"sourceCodeEnd":884,"githubUrl":"https://github.com/jdx/mise/blob/afd2eddd3a50c16190efc1c7e94404b48f72af57/src/system/systemd.rs#L848-L884","documentation":"This is the generic wrapper for failures of `systemctl --user <args>` invocations made by mise's systemd integration. When the systemctl child process exits non-zero, mise bails with the exact argument list and the trimmed stderr from systemctl, so the underlying systemd error is preserved in the message. A separate timeout variant exists if systemctl hangs.","triggerScenarios":"Any mise operation that shells out to `systemctl --user` (enable/start/daemon-reload/etc. for managed units) where systemctl exits non-zero — e.g. daemon-reload on a unit with a syntax error, starting a unit whose ExecStart binary is missing, or running without a user session/bus.","commonSituations":"Malformed generated unit files; missing executable referenced by `exec_start`; no user D-Bus/session in SSH or container contexts (`Failed to connect to bus`); `systemctl` not installed or systemd not running (e.g. WSL1, plain Docker without systemd); unit masked or dependency failed.","solutions":["Read the stderr portion of the message — it contains systemctl's actual reason — and fix the unit config accordingly.","Run `systemctl --user status <unit>` and `journalctl --user -u <unit>` to inspect the failure.","Ensure a user systemd session exists (`loginctl enable-linger $USER`; in SSH/containers verify `systemctl --user` works at all and DBUS_SESSION_BUS_ADDRESS/XDG_RUNTIME_DIR are set).","Verify `exec_start` points to an existing, executable binary.","Run `systemctl --user daemon-reload` after editing unit files."],"exampleFix":"# message: `systemctl --user start myapp.service` failed: Failed to connect to bus: No such file or directory\n# before: SSH session without lingering\nloginctl enable-linger $USER\nexport XDG_RUNTIME_DIR=/run/user/$(id -u)\n# after: systemctl --user can reach the user bus","handlingStrategy":"try-catch","validationCode":"// preflight: is user systemd reachable at all?\nconst { execSync } = require('child_process');\nfunction userSystemdReachable() {\n  try { execSync('systemctl --user is-system-running', { stdio: 'ignore' }); return true; }\n  catch (e) { return e.status !== 1 ? false : true; } // degraded still counts\n}","typeGuard":null,"tryCatchPattern":"// Rust caller\nmatch run_systemctl(&[\"start\", \"myapp.service\"]).await {\n    Ok(()) => {}\n    Err(e) => {\n        eprintln!(\"systemctl failed: {e:#}\");\n        // inspect `journalctl --user -u myapp` and fix the unit before retrying\n    }\n}","preventionTips":["Run `systemctl --user daemon-reload` after any unit-file change.","Enable linger (`loginctl enable-linger $USER`) for headless/SSH user services.","Verify `exec_start` binaries exist and are executable before enabling units.","In containers, confirm systemd is actually PID 1 or skip user units."],"tags":["systemd","systemctl","process-exit","subprocess"],"backgroundTag":"command-failed","analyzedSha":"afd2eddd3a50c16190efc1c7e94404b48f72af57","analyzedAt":"2026-09-09T01:38:25.179Z","contentChangedAt":"2026-09-09T01:38:25.179Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}