{"record":{"id":"8399e32bf5175dd6","repo":"chenhg5/cc-connect","slug":"systemd-user-session-not-available-in-wsl2-add","errorCode":null,"errorMessage":"systemd user session not available in WSL2.\n  Add the following to /etc/wsl.conf and restart WSL (wsl --shutdown):\n    [boot]\n    systemd=true\n  Or use: nohup cc-connect > cc-connect.log 2>&1 &","messagePattern":"systemd user session not available in WSL2\\.\n  Add the following to /etc/wsl\\.conf and restart WSL \\(wsl --shutdown\\):\n    \\[boot\\]\n    systemd=true\n  Or use: nohup cc-connect > cc-connect\\.log 2>&1 &","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":294,"sourceCode":"\t\t\treturn fmt.Errorf(\"systemd is not active in this WSL2 instance.\\n\" +\n\t\t\t\t\"  Add the following to /etc/wsl.conf and restart WSL (wsl --shutdown):\\n\" +\n\t\t\t\t\"    [boot]\\n\" +\n\t\t\t\t\"    systemd=true\\n\" +\n\t\t\t\t\"  Or use: nohup cc-connect > cc-connect.log 2>&1 &\")\n\t\t}\n\t\tif state == \"offline\" || strings.Contains(state, \"not been booted\") {\n\t\t\treturn fmt.Errorf(\"systemd is not active (state: %s).\\n\"+\n\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 {","sourceCodeStart":276,"sourceCodeEnd":312,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L276-L312","documentation":"On WSL2, cc-connect's daemon support needs systemd's user session (systemctl --user) to manage the service. This error is thrown when the WSL2 check in checkSystemdRunning determines the user-level systemd session is not available — almost always because systemd is disabled in /etc/wsl.conf. The message contains the exact wsl.conf snippet needed to enable it.","triggerScenarios":"Running `cc-connect daemon install` inside WSL2 where /etc/wsl.conf lacks the `[boot] systemd=true` directive, so `systemctl --user` has no user session/manager to talk to.","commonSituations":"Default WSL2 distributions (systemd is off by default on older WSL releases); freshly installed WSL distros where wsl.conf was never edited; users who enabled system-level systemd but not the user session.","solutions":["Add the following to /etc/wsl.conf:\n[boot]\nsystemd=true\nthen restart WSL with `wsl --shutdown` and reopen your distro","Verify afterwards: `systemctl is-system-running` and `systemctl --user status` both respond","Require a recent WSL version (`wsl --update`) since systemd support needs WSL 0.67.6+ / Windows 11 or backported support","If you cannot enable systemd, use `nohup cc-connect > cc-connect.log 2>&1 &` instead of the daemon subcommand"],"exampleFix":"// before: /etc/wsl.conf without systemd\n// after:\n$ sudo tee -a /etc/wsl.conf >/dev/null <<'EOF'\n[boot]\nsystemd=true\nEOF\n$ wsl --shutdown   # from PowerShell, then reopen WSL\n$ cc-connect daemon install","handlingStrategy":"validation","validationCode":"if grep -qs '^\\[boot\\]' /etc/wsl.conf && grep -qsA1 '^\\[boot\\]' /etc/wsl.conf | grep -qs 'systemd=true'; then\n  cc-connect daemon install\nelse\n  echo \"Enable systemd in /etc/wsl.conf ([boot] systemd=true), run 'wsl --shutdown', then retry\"\nfi","typeGuard":null,"tryCatchPattern":"if err := daemon.Install(cfg); err != nil && strings.Contains(err.Error(), \"WSL2\") {\n    fmt.Fprintln(os.Stderr, \"Enable systemd: add '[boot]\\nsystemd=true' to /etc/wsl.conf, then run 'wsl --shutdown'\")\n    os.Exit(1)\n}","preventionTips":["Enable systemd=true in /etc/wsl.conf immediately after installing any WSL distro you plan to run services in","Pin a recent WSL version (`wsl --update`) since systemd support requires WSL >= 0.67.6","After every `wsl --shutdown`, verify `systemctl --user status` works before running daemon commands","Automate WSL provisioning with a check for /etc/wsl.conf systemd=true"],"tags":["daemon","systemd","wsl2","windows","process-management"],"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"}