{"record":{"id":"1042bb71bbca0506","repo":"chenhg5/cc-connect","slug":"stop-s-w-1042bb","errorCode":null,"errorMessage":"stop: %s (%w)","messagePattern":"stop: (.+?) \\(%w\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":116,"sourceCode":"\n\tif _, err := runSystemctl(m.sysArgs(\"daemon-reload\")...); err != nil {\n\t\tslog.Warn(\"systemd: daemon-reload failed\", \"error\", err)\n\t}\n\treturn nil\n}\n\nfunc (m *systemdManager) Start() error {\n\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","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L98-L134","documentation":"Stop() wraps a failure of `systemctl stop cc-connect`, including systemctl's stdout. It means the service could not be stopped, typically because systemctl cannot reach the systemd manager or the unit is not loaded.","triggerScenarios":"Calling Stop when systemd is not running, the unit was never installed/loaded, or the caller lacks privileges; also during shutdown when the system manager is going away.","commonSituations":"Calling Stop from within the service itself in a constrained environment; unit already removed but Stop invoked on stale state; WSL2 session where systemd isn't PID 1.","solutions":["Read the embedded stdout; if it says the unit is not loaded, treat the service as already stopped.","Verify systemd is reachable: `systemctl is-system-running`.","Run with sufficient privileges (sudo) for system units.","Fall back gracefully: check `systemctl is-active cc-connect` before/after Stop."],"exampleFix":"// before\nmgr.Stop() // stop: Unit cc-connect.service not loaded.\n// after\nif out, err := mgr.Stop(); err != nil && strings.Contains(out, \"not loaded\") {\n    return nil // already stopped\n} else if err != nil {\n    return err\n}","handlingStrategy":"try-catch","validationCode":"active, err := exec.Command(\"systemctl\", \"is-active\", \"cc-connect\").Output()\nif err == nil && strings.TrimSpace(string(active)) == \"inactive\" {\n    return nil // already stopped\n}","typeGuard":"func serviceLoaded() bool {\n    out, err := exec.Command(\"systemctl\", \"is-active\", \"cc-connect\").Output()\n    return err == nil && strings.TrimSpace(string(out)) != \"unknown\"\n}","tryCatchPattern":"if err := mgr.Stop(); err != nil {\n    if strings.Contains(err.Error(), \"not loaded\") {\n        return nil // idempotent stop\n    }\n    return err\n}","preventionTips":["Make Stop calls idempotent: ignore 'unit not loaded' errors.","Verify systemd reachability before stop operations.","Don't call Stop from inside the service's own ExecStart process path.","Use `systemctl is-active` as a pre-check."],"tags":["systemd","go","service","process"],"backgroundTag":"connection-refused","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"}