{"record":{"id":"6a15b7a1ab75a87a","repo":"chenhg5/cc-connect","slug":"systemd-check-failed-state-s-use-nohup-as-a","errorCode":null,"errorMessage":"systemd check failed (state: %s).\n  Use nohup as alternative: nohup cc-connect > cc-connect.log 2>&1 &","messagePattern":"systemd check failed \\(state: (.+?)\\)\\.\n  Use nohup as alternative: nohup cc-connect > cc-connect\\.log 2>&1 &","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":288,"sourceCode":"\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\" +\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\"+","sourceCodeStart":270,"sourceCodeEnd":306,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L270-L306","documentation":"This is the fallback branch of checkSystemdRunning in daemon/systemd.go: the systemd state query returned a value that is neither \"running\" nor the offline/not-booted cases handled earlier, so the exact cause is unknown but systemd is unusable. cc-connect refuses to install a systemd unit because systemctl operations would fail. The message recommends nohup as a direct alternative.","triggerScenarios":"`cc-connect daemon install` when `systemctl is-system-running` returns an unexpected/degraded state such as \"degraded\", \"maintenance\", \"stopping\", or an empty/unparseable response that still indicates systemd is not fully operational.","commonSituations":"A system booting in degraded state after a failed unit; a system currently shutting down; a systemd build whose is-system-running output cc-connect does not recognize; NixOS or custom init scripts emitting unusual state strings.","solutions":["Diagnose the reported state: run `systemctl is-system-running` and `systemctl --failed` to see why systemd is degraded, and fix the failing units","If the system is mid-boot/shutdown, retry the daemon install once systemd reaches running state","Fall back to `nohup cc-connect > cc-connect.log 2>&1 &` or tmux/screen as the error suggests","If the state string looks valid but is still rejected, report it upstream so checkSystemdRunning can whitelist it (e.g. treat \"degraded\" as usable)"],"exampleFix":"// before\n$ cc-connect daemon install\n// error: systemd check failed (state: degraded)\n// after: repair systemd or bypass\n$ systemctl --failed   # fix failing units\n$ sudo systemctl reset-failed\n$ cc-connect daemon install\n// or: nohup cc-connect > cc-connect.log 2>&1 &","handlingStrategy":"fallback","validationCode":"state=$(systemctl is-system-running 2>/dev/null || true)\ncase \"$state\" in\n  running) cc-connect daemon install ;;\n  *) echo \"systemd state '$state' unusable; falling back to nohup\"; nohup cc-connect > cc-connect.log 2>&1 & ;;\nesac","typeGuard":null,"tryCatchPattern":"if err := daemon.Install(cfg); err != nil {\n    var unsupported *daemon.SystemdStateError\n    if errors.As(err, &unsupported) {\n        slog.Warn(\"systemd not fully operational, using nohup fallback\", \"state\", unsupported.State)\n        return runWithNohup(cfg)\n    }\n    return fmt.Errorf(\"daemon install: %w\", err)\n}","preventionTips":["Monitor `systemctl is-system-running` and fix degraded units before installing services","Add systemd health checks to deployment scripts prior to any daemon install step","Keep a nohup/tmux fallback command documented for environments with flaky systemd","Retry daemon install after boot completes if the system was mid-startup"],"tags":["daemon","systemd","linux","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-14T00:17:10.932Z"}