{"record":{"id":"bf80cc44c2af34a8","repo":"spacedriveapp/spacedrive","slug":"failed-to-start-systemd-service","errorCode":null,"errorMessage":"Failed to start systemd service: {}","messagePattern":"Failed to start systemd service: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"apps/cli/src/domains/daemon/mod.rs","lineNumber":348,"sourceCode":"\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));\n\t}\n\n\tprintln!(\"Daemon installed and started successfully!\");\n\tprintln!(\"The daemon will start automatically on login.\");\n\tprintln!();\n\tprintln!(\"Useful commands:\");\n\tprintln!(\"  systemctl --user status {}\", service_name);\n\tprintln!(\"  journalctl --user -u {} -f\", service_name);\n\n\tOk(())\n}\n\n#[cfg(target_os = \"linux\")]\nasync fn uninstall_launchd_service(instance: Option<String>) -> Result<()> {\n\tuse std::fs;","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/spacedriveapp/spacedrive/blob/6dfeccf2113039e35f2ce735f945e70dc3e4ea45/apps/cli/src/domains/daemon/mod.rs#L330-L366","documentation":"The final step of Linux install runs `systemctl --user start spacedrive-daemon.service`. The unit was enabled, but the start request failed: either systemd rejected the unit (bad ExecStart path, invalid data-dir) or the service started and exited immediately with a non-zero result. The CLI surfaces systemctl's stderr, which for start failures is often terse, so the real cause lives in the journal.","triggerScenarios":"sd-daemon binary moved or deleted between enable and start; the `--data-dir` directory not writable by the user; the daemon crashing at startup (port/socket already in use, invalid instance flag) so systemd reports a failed start.","commonSituations":"Reinstalling while an older daemon instance already owns the socket; unit file edited by hand after install without daemon-reload; data directory on a read-only or permission-restricted mount.","solutions":["Get the real failure from the journal: `journalctl --user -u spacedrive-daemon -e --no-pager`.","Check unit state and ExecStart resolution: `systemctl --user status spacedrive-daemon`.","Ensure the data dir exists and is writable: `mkdir -p <data-dir> && touch <data-dir>/.write-test`.","Stop anything holding the old daemon (`systemctl --user stop spacedrive-daemon; pkill sd-daemon`) and `systemctl --user daemon-reload` before retrying install."],"exampleFix":"# before\nsd-cli daemon install  # -> Failed to start systemd service: Job for spacedrive-daemon.service failed\n\n# after diagnosing\njournalctl --user -u spacedrive-daemon -e   # shows e.g. 'address already in use'\nsystemctl --user stop spacedrive-daemon && pkill -x sd-daemon\nsd-cli daemon install  # -> Daemon installed and started successfully!","handlingStrategy":"try-catch","validationCode":"# after a failed start, the journal carries the real cause\njournalctl --user -u spacedrive-daemon -e --no-pager | tail -50","typeGuard":null,"tryCatchPattern":"if let Err(e) = install_autostart().await {\n    if e.to_string().contains(\"Failed to start systemd service\") {\n        let _ = std::process::Command::new(\"journalctl\")\n            .args([\"--user\", \"-u\", \"spacedrive-daemon\", \"-e\", \"--no-pager\"]).status();\n    }\n    return Err(e);\n}","preventionTips":["Stop existing daemon processes before installing (`systemctl --user stop spacedrive-daemon; pkill -x sd-daemon`).","Make sure the --data-dir you configured at install time is writable.","After hand-editing the unit, run `systemctl --user daemon-reload` so start uses the new file."],"tags":["linux","systemd","daemon","journalctl","startup"],"backgroundTag":null,"analyzedSha":"6dfeccf2113039e35f2ce735f945e70dc3e4ea45","analyzedAt":"2026-08-16T11:26:17.074Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}