{"record":{"id":"886a9ed108bb93c3","repo":"chenhg5/cc-connect","slug":"systemd-user-session-not-available-this-often-h","errorCode":null,"errorMessage":"systemd user session not available.\n  This often happens when connecting via SSH without a systemd login session.\n  Try one of:\n    1. Run as root: sudo cc-connect daemon install (uses system-level systemd)\n    2. loginctl enable-linger %s && export XDG_RUNTIME_DIR=/run/user/$(id -u)\n    3. Use nohup/tmux instead: nohup cc-connect > cc-connect.log 2>&1 &","messagePattern":"systemd user session not available\\.\n  This often happens when connecting via SSH without a systemd login session\\.\n  Try one of:\n    1\\. Run as root: sudo cc-connect daemon install \\(uses system-level systemd\\)\n    2\\. loginctl enable-linger (.+?) && export XDG_RUNTIME_DIR=/run/user/\\$\\(id -u\\)\n    3\\. Use nohup/tmux instead: nohup cc-connect > cc-connect\\.log 2>&1 &","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":302,"sourceCode":"\t\t\t\t\"  If running in a container, systemd is typically not available.\\n\"+\n\t\t\t\t\"  Use nohup, tmux, or screen instead:\\n\"+\n\t\t\t\t\"    nohup cc-connect > cc-connect.log 2>&1 &\", state)\n\t\t}\n\t\treturn fmt.Errorf(\"systemd check failed (state: %s).\\n\"+\n\t\t\t\"  Use nohup as alternative: nohup cc-connect > cc-connect.log 2>&1 &\", state)\n\t}\n\n\t// User-level failures\n\tif wsl {\n\t\treturn fmt.Errorf(\"systemd user session not available in WSL2.\\n\" +\n\t\t\t\"  Add the following to /etc/wsl.conf and restart WSL (wsl --shutdown):\\n\" +\n\t\t\t\"    [boot]\\n\" +\n\t\t\t\"    systemd=true\\n\" +\n\t\t\t\"  Or use: nohup cc-connect > cc-connect.log 2>&1 &\")\n\t}\n\n\tuser := os.Getenv(\"USER\")\n\treturn fmt.Errorf(\"systemd user session not available.\\n\"+\n\t\t\"  This often happens when connecting via SSH without a systemd login session.\\n\"+\n\t\t\"  Try one of:\\n\"+\n\t\t\"    1. Run as root: sudo cc-connect daemon install (uses system-level systemd)\\n\"+\n\t\t\"    2. loginctl enable-linger %s && export XDG_RUNTIME_DIR=/run/user/$(id -u)\\n\"+\n\t\t\"    3. Use nohup/tmux instead: nohup cc-connect > cc-connect.log 2>&1 &\", user)\n}\n\nfunc isWSL2() bool {\n\tdata, err := os.ReadFile(\"/proc/version\")\n\tif err != nil {\n\t\treturn false\n\t}\n\tlower := strings.ToLower(string(data))\n\treturn strings.Contains(lower, \"microsoft\") || strings.Contains(lower, \"wsl\")\n}\n\nfunc parseKeyValue(text string) map[string]string {\n\tm := make(map[string]string)","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L284-L320","documentation":"cc-connect installs its daemon as a systemd *user* unit on Linux, which requires an active systemd user session for the current user. This error is thrown when the user-level systemd manager is unreachable even though system systemd is running — classically over SSH, where no PAM login session (and thus no /run/user/<uid> bus) is created. The message lists three concrete remediations including running at system level with sudo, enabling linger, or falling back to nohup/tmux.","triggerScenarios":"`cc-connect daemon install` over an SSH session (or cron/su without full PAM session) where XDG_RUNTIME_DIR is unset and `systemctl --user` fails with \"Failed to connect to bus\"; or where the user has no lingering session so the user manager only exists during graphical login.","commonSituations":"SSH into a headless server and trying to install the daemon; switching users with `su` (loses the systemd session); deploying via CI/SSH scripts; user account created without a login session ever started.","solutions":["Enable linger so the user manager runs without login: `sudo loginctl enable-linger $USER`","Ensure the session bus env is set: `export XDG_RUNTIME_DIR=/run/user/$(id -u)` (and `export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus`), then retry","Install at system level instead: `sudo cc-connect daemon install`","Use `nohup cc-connect > cc-connect.log 2>&1 &` or tmux if systemd user sessions are intentionally disabled on the host"],"exampleFix":"// before: over SSH\n$ cc-connect daemon install\n// error: systemd user session not available\n// after\n$ sudo loginctl enable-linger $USER\n$ export XDG_RUNTIME_DIR=/run/user/$(id -u)\n$ cc-connect daemon install","handlingStrategy":"validation","validationCode":"if [ -z \"$XDG_RUNTIME_DIR\" ] || [ ! -d \"$XDG_RUNTIME_DIR\" ]; then\n  sudo loginctl enable-linger \"$USER\"\n  export XDG_RUNTIME_DIR=/run/user/$(id -u)\nfi\nsystemctl --user status >/dev/null 2>&1 || { echo \"no systemd user session; use sudo cc-connect daemon install\"; exit 1; }\ncc-connect daemon install","typeGuard":null,"tryCatchPattern":"if err := daemon.Install(cfg); err != nil && strings.Contains(err.Error(), \"user session not available\") {\n    // escalate to system-level install or fall back to nohup\n    return runPrivilegedInstallOrNohup(cfg)\n}","preventionTips":["Enable linger for service accounts: `sudo loginctl enable-linger <user>` so the user manager exists without a login session","Always export XDG_RUNTIME_DIR (and DBUS_SESSION_BUS_ADDRESS) in SSH/CI scripts before systemctl --user operations","Prefer `sudo cc-connect daemon install` (system-level unit) on headless servers without graphical logins","Avoid `su` when managing user units; use `machinectl shell` or full SSH login sessions that create PAM sessions"],"tags":["daemon","systemd","ssh","linux","linger"],"backgroundTag":"systemd-unavailable","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}