{"record":{"id":"061b039624e03dd8","repo":"chenhg5/cc-connect","slug":"systemctl-s-s-w","errorCode":null,"errorMessage":"systemctl %s: %s (%w)","messagePattern":"systemctl (.+?): (.+?) \\(%w\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"daemon/systemd.go","lineNumber":82,"sourceCode":"\t// units (/etc/systemd/system/) the file is owned by root and remains\n\t// readable by root only; for user-level units under\n\t// ~/.config/systemd/user it remains owner-only. WriteFile only applies\n\t// perm on create, so Chmod afterwards is required to harden reinstalls\n\t// of pre-existing 0644 units from earlier cc-connect versions.\n\tif err := os.WriteFile(unitPath, []byte(unit), 0600); err != nil {\n\t\treturn fmt.Errorf(\"write unit file: %w\", err)\n\t}\n\tif err := os.Chmod(unitPath, 0600); err != nil {\n\t\treturn fmt.Errorf(\"chmod unit file: %w\", err)\n\t}\n\n\tfor _, cmdArgs := range [][]string{\n\t\tm.sysArgs(\"daemon-reload\"),\n\t\tm.sysArgs(\"enable\", systemdServiceName),\n\t\tm.sysArgs(\"restart\", systemdServiceName),\n\t} {\n\t\tif out, err := runSystemctl(cmdArgs...); err != nil {\n\t\t\treturn fmt.Errorf(\"systemctl %s: %s (%w)\", strings.Join(cmdArgs, \" \"), out, err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (m *systemdManager) Uninstall() error {\n\tif _, err := runSystemctl(m.sysArgs(\"disable\", \"--now\", systemdServiceName)...); err != nil {\n\t\tslog.Warn(\"systemd: disable failed\", \"error\", err)\n\t}\n\n\tunitPath := m.unitPath()\n\tif err := os.Remove(unitPath); err != nil && !os.IsNotExist(err) {\n\t\treturn fmt.Errorf(\"remove unit: %w\", err)\n\t}\n\n\tif _, err := runSystemctl(m.sysArgs(\"daemon-reload\")...); err != nil {\n\t\tslog.Warn(\"systemd: daemon-reload failed\", \"error\", err)","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/daemon/systemd.go#L64-L100","documentation":"Install() wraps a failure of one of the three systemctl commands it runs: daemon-reload, enable, restart. The error message embeds the joined args, the command's stdout, and the underlying error, so it usually says exactly which systemctl step failed and why.","triggerScenarios":"systemctl is missing or the system instance is unreachable; the generated unit file is invalid and enable/restart rejects it; the service fails to start (bad ExecStart, port already in use, missing binary); running without privileges.","commonSituations":"WSL2 without systemd enabled (systemctl fails with 'System has not been booted with systemd'); syntax error in unit from malformed config values; cc-connect binary path moved after install; editing config.toml with a value that breaks the unit.","solutions":["Read the embedded stdout in the error — it names the failing step and systemctl's reason.","Verify systemd is PID 1: `ps -p 1`; in WSL2 enable [boot] systemd=true in /etc/wsl.conf.","Inspect the unit: `systemctl status cc-connect` and `journalctl -u cc-connect -e`.","Validate the unit and service: `systemd-analyze verify <unitPath>`; fix config and reinstall."],"exampleFix":"// before\nmgr.Install(cfg) // systemctl restart cc-connect: ... (exit status 1) — bad ExecStart\n// after\nif err := mgr.Install(cfg); err != nil {\n    slog.Error(\"install failed\", \"error\", err) // inspect embedded systemctl output\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if err := exec.Command(\"systemctl\", \"is-system-running\").Run(); err != nil {\n    return fmt.Errorf(\"systemd not operational: %w\", err)\n}\nif _, err := os.Stat(mgr.unitPath()); err != nil {\n    return fmt.Errorf(\"unit not installed yet\")\n}","typeGuard":"func systemdAvailable() bool {\n    return exec.Command(\"systemctl\", \"is-system-running\").Run() == nil\n}","tryCatchPattern":"if err := mgr.Install(cfg); err != nil {\n    if strings.Contains(err.Error(), \"systemctl\") {\n        // error message embeds args + stdout: log it verbatim for diagnosis\n        slog.Error(\"systemctl step failed\", \"detail\", err.Error())\n    }\n    return err\n}","preventionTips":["Confirm systemd is PID 1 (ps -p 1) before daemon management.","Enable [boot] systemd=true in WSL2 before installing.","Validate generated unit content with systemd-analyze verify.","Keep the cc-connect binary path stable between install and restart."],"tags":["systemd","go","process","service"],"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"}