{"record":{"id":"8dd4ca006f006f12","repo":"chenhg5/cc-connect","slug":"restart-s-w-8dd4ca","errorCode":null,"errorMessage":"restart: %s (%w)","messagePattern":"restart: (.+?) \\(%w\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":124,"sourceCode":"\tout, err := runSystemctl(m.sysArgs(\"start\", systemdServiceName)...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"start: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Stop() error {\n\tout, err := runSystemctl(m.sysArgs(\"stop\", systemdServiceName)...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"stop: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Restart() error {\n\tout, err := runSystemctl(m.sysArgs(\"restart\", systemdServiceName)...)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"restart: %s (%w)\", out, err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Status() (*Status, error) {\n\tst := &Status{Platform: m.Platform()}\n\n\tunitPath := m.unitPath()\n\tif _, err := os.Stat(unitPath); err != nil {\n\t\treturn st, nil\n\t}\n\tst.Installed = true\n\n\tout, err := runSystemctl(m.sysArgs(\"show\", systemdServiceName,\n\t\t\"--no-page\", \"--property\", \"ActiveState,MainPID\")...)\n\tif err != nil {\n\t\treturn st, nil\n\t}","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L106-L142","documentation":"Restart() wraps a failure of `systemctl restart cc-connect`, embedding systemctl's stdout. Restart implies both stop and start, so it fails if either half fails: unreachable systemd, invalid unit, or the service failing to come back up after stopping.","triggerScenarios":"Calling Restart after a config change that produced a broken unit; systemd unreachable; the new process fails at startup (bad config value, port conflict, missing agent CLI).","commonSituations":"Editing config.toml with a typo then restarting the service; upgrading cc-connect to a binary path that no longer exists; WSL2 without systemd enabled.","solutions":["Read the embedded systemctl stdout to see the stop/start failure reason.","Check unit validity: `systemd-analyze verify /etc/systemd/system/cc-connect.service`.","Inspect post-restart logs: `journalctl -u cc-connect -e`.","If restart-after-edit broke it, revert config.toml, reinstall, and restart."],"exampleFix":"// before\nmgr.Restart() // restart: Job for cc-connect.service failed because the control process exited with error code\n// after\nif err := mgr.Restart(); err != nil {\n    out, _ := exec.Command(\"journalctl\", \"-u\", \"cc-connect\", \"-n\", \"20\", \"--no-pager\").Output()\n    return fmt.Errorf(\"restart failed: %w; logs: %s\", err, out)\n}","handlingStrategy":"try-catch","validationCode":"if err := exec.Command(\"systemd-analyze\", \"verify\", mgr.unitPath()).Run(); err != nil {\n    return fmt.Errorf(\"unit invalid; fix config before restart: %w\", err)\n}\nif err := exec.Command(\"systemctl\", \"is-system-running\").Run(); err != nil {\n    return fmt.Errorf(\"systemd not running: %w\", err)\n}","typeGuard":"func restartSafe(mgr *systemdManager) bool {\n    return exec.Command(\"systemd-analyze\", \"verify\", mgr.unitPath()).Run() == nil &&\n        exec.Command(\"systemctl\", \"is-system-running\").Run() == nil\n}","tryCatchPattern":"if err := mgr.Restart(); err != nil {\n    out, _ := exec.Command(\"journalctl\", \"-u\", \"cc-connect\", \"-n\", \"20\", \"--no-pager\").Output()\n    return fmt.Errorf(\"restart: %w\\nrecent logs:\\n%s\", err, out)\n}","preventionTips":["Validate config.toml changes before restarting the service.","Run systemd-analyze verify after every reinstall.","Keep the agent CLI path valid for the service user.","Watch journalctl after restart to catch immediate exit loops."],"tags":["systemd","go","service","process"],"backgroundTag":"git-command-failed","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"}