{"record":{"id":"a9bade9eaae29ff3","repo":"spacedriveapp/spacedrive","slug":"failed-to-enable-systemd-service","errorCode":null,"errorMessage":"Failed to enable systemd service: {}","messagePattern":"Failed to enable systemd service: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/domains/daemon/mod.rs","lineNumber":333,"sourceCode":"\n\tprintln!(\"Created systemd service: {}\", service_path.display());\n\n\t// Reload systemd daemon\n\tlet _ = std::process::Command::new(\"systemctl\")\n\t\t.arg(\"--user\")\n\t\t.arg(\"daemon-reload\")\n\t\t.output();\n\n\t// Enable the service\n\tlet output = std::process::Command::new(\"systemctl\")\n\t\t.arg(\"--user\")\n\t\t.arg(\"enable\")\n\t\t.arg(&service_name)\n\t\t.output()?;\n\n\tif !output.status.success() {\n\t\tlet stderr = String::from_utf8_lossy(&output.stderr);\n\t\treturn Err(anyhow::anyhow!(\n\t\t\t\"Failed to enable systemd service: {}\",\n\t\t\tstderr\n\t\t));\n\t}\n\n\t// Start the service\n\tlet output = std::process::Command::new(\"systemctl\")\n\t\t.arg(\"--user\")\n\t\t.arg(\"start\")\n\t\t.arg(&service_name)\n\t\t.output()?;\n\n\tif !output.status.success() {\n\t\tlet stderr = String::from_utf8_lossy(&output.stderr);\n\t\treturn Err(anyhow::anyhow!(\n\t\t\t\"Failed to start systemd service: {}\",\n\t\t\tstderr\n\t\t));","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/domains/daemon/mod.rs#L315-L351","documentation":"During Linux install, after writing the unit and running `systemctl --user daemon-reload`, the CLI runs `systemctl --user enable spacedrive-daemon.service` and requires success. A non-zero exit means the systemd user instance could not process the request, and its stderr is included in the message. Note the daemon-reload result is intentionally ignored (`.output()` without `?`), so this enable step is the first hard checkpoint.","triggerScenarios":"`systemctl --user` over SSH when there is no user bus (XDG_RUNTIME_DIR unset, no lingering enabled); running inside a container or WSL distro where systemd is not PID 1; unit name resolution failing because the unit file was written under a different name (instance variant `spacedrive-daemon@<inst>.service`).","commonSituations":"Headless servers accessed via SSH; Docker/LXC containers without systemd; WSL before enabling `[boot] systemd=true` in /etc/wsl.conf; fresh boot where the user manager is not running.","solutions":["Verify the user manager works in that exact shell: `systemctl --user status`; if it errors about D-Bus or XDG_RUNTIME_DIR, fix that first.","Over SSH, set `export XDG_RUNTIME_DIR=/run/user/$(id -u)` and `export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus`, or enable lingering so the user manager persists: `sudo loginctl enable-linger $USER`.","On WSL, add `[boot]\\nsystemd=true` to /etc/wsl.conf and restart the distro (`wsl --shutdown`).","Read the stderr embedded in the message; for invalid units inspect `systemctl --user cat spacedrive-daemon`."],"exampleFix":"# before (headless SSH, no user bus)\nsd-cli daemon install  # -> Failed to enable systemd service: Failed to connect to bus: ...\n\n# after\nsudo loginctl enable-linger $USER\nexport XDG_RUNTIME_DIR=/run/user/$(id -u)\nsd-cli daemon install  # -> Daemon installed and started successfully!","handlingStrategy":"validation","validationCode":"# preflight: a functional systemd user manager is required\nsystemctl --user is-system-running >/dev/null 2>&1 || { echo 'no user systemd session' >&2; exit 1; }\nsd-cli daemon install","typeGuard":null,"tryCatchPattern":"match install_autostart().await {\n    Err(e) if e.to_string().contains(\"Failed to enable systemd service\") => {\n        // unit file is already written; retry enable manually after fixing the bus\n        run!(\"systemctl --user enable spacedrive-daemon.service\")?;\n        run!(\"systemctl --user start spacedrive-daemon.service\")?;\n    }\n    other => other?,\n}","preventionTips":["Over SSH: `export XDG_RUNTIME_DIR=/run/user/$(id -u)` or `sudo loginctl enable-linger $USER` so the user manager exists.","On WSL enable systemd in /etc/wsl.conf before using daemon install.","Test with `systemctl --user status` first; if that fails, install will too."],"tags":["linux","systemd","systemctl","dbus","daemon"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}