{"record":{"id":"d869cad3f8f8f00a","repo":"chenhg5/cc-connect","slug":"systemd-is-not-active-in-this-wsl2-instance-add","errorCode":null,"errorMessage":"systemd is not active in this WSL2 instance.\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 is not active in this WSL2 instance\\.\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":276,"sourceCode":"\t\targs = []string{\"--user\", \"is-system-running\"}\n\t}\n\n\tout, _ := runSystemctl(args...)\n\tstate := strings.TrimSpace(strings.ToLower(out))\n\n\t// These states all mean systemd is usable for managing services\n\tswitch state {\n\tcase \"running\", \"degraded\", \"starting\", \"initializing\":\n\t\treturn nil\n\t}\n\n\t// \"offline\" = systemd exists but is not PID 1 (WSL2 without systemd, some containers)\n\t// \"not been booted\" / empty = no systemd at all\n\twsl := isWSL2()\n\n\tif system {\n\t\tif wsl {\n\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\" +","sourceCodeStart":258,"sourceCodeEnd":294,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L258-L294","documentation":"checkSystemdRunning detects that a systemd binary exists but is not PID 1 in a WSL2 instance, i.e. systemd was never enabled for that distro. Instead of a bare error it returns a detailed, multi-line message telling the user to enable [boot] systemd=true in /etc/wsl.conf and restart WSL, or fall back to running cc-connect with nohup. newPlatformManager surfaces this whenever daemon management is attempted in such an environment.","triggerScenarios":"Running any cc-connect daemon command (install/start/restart/status) inside WSL2 where systemctl exists but `systemctl is-system-running` reports the system as offline/not booted, because /etc/wsl.conf lacks [boot] systemd=true.","commonSituations":"Fresh WSL2 Ubuntu install (systemd disabled by default on older WSL releases); a WSL distro where the user never enabled systemd; Docker containers sharing the WSL2 VM without systemd.","solutions":["Enable systemd in WSL: add `[boot]\\nsystemd=true` under /etc/wsl.conf, then run `wsl --shutdown` from Windows and reopen the distro.","Update WSL itself (`wsl --update`) — newer WSL versions default systemd on for new distros.","Use the suggested fallback: `nohup cc-connect > cc-connect.log 2>&1 &` to run without systemd.","If this is actually a plain container (not WSL2), use a container-appropriate supervisor instead of the systemd manager."],"exampleFix":"// before\n$ cc-connect install\n# systemd is not active in this WSL2 instance...\n// after (in WSL)\n$ printf '[boot]\\nsystemd=true\\n' | sudo tee -a /etc/wsl.conf\n$ wsl --shutdown   # from Windows, then reopen WSL\n$ cc-connect install","handlingStrategy":"fallback","validationCode":"out, err := exec.Command(\"systemctl\", \"is-system-running\").Output()\nstate := strings.TrimSpace(string(out))\nif err != nil || state == \"offline\" || strings.Contains(state, \"not been booted\") {\n    return fmt.Errorf(\"systemd not active; enable [boot] systemd=true in /etc/wsl.conf or use nohup fallback\")\n}","typeGuard":"func systemdActive() bool {\n    out, err := exec.Command(\"systemctl\", \"is-system-running\").Output()\n    s := strings.TrimSpace(string(out))\n    return err == nil && s == \"running\" || s == \"degraded\"\n}","tryCatchPattern":"if err := mgr.Install(cfg); err != nil {\n    if strings.Contains(err.Error(), \"WSL2\") {\n        // fall back to nohup-style process management\n        return startNohup(cfg)\n    }\n    return err\n}","preventionTips":["Enable [boot] systemd=true in /etc/wsl.conf on all WSL2 dev machines.","Run `wsl --update` to get systemd-by-default WSL releases.","Keep a nohup fallback path in scripts for systemd-less environments.","Check `systemctl is-system-running` before any daemon management command."],"tags":["wsl2","systemd","environment","daemon"],"backgroundTag":"unsupported-platform","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"}