Stop sends SIGTERM to the daemon process
(root string)
| 134 | |
| 135 | // Stop sends SIGTERM to the daemon process |
| 136 | func Stop(root string) error { |
| 137 | pid, err := ReadPID(root) |
| 138 | if err != nil { |
| 139 | return fmt.Errorf("no daemon running: %w", err) |
| 140 | } |
| 141 | proc, err := os.FindProcess(pid) |
| 142 | if err != nil { |
| 143 | return err |
| 144 | } |
| 145 | // terminateDaemon is platform-specific: SIGTERM on Unix; on Windows it |
| 146 | // verifies the PID belongs to this repo's daemon (guarding against a reused |
| 147 | // stale PID) before killing, returning ErrForeignDaemonPID otherwise. |
| 148 | if err := terminateDaemon(root, proc); err != nil { |
| 149 | if errors.Is(err, ErrForeignDaemonPID) { |
| 150 | // The recorded PID isn't our daemon (stale or reused). Clear the |
| 151 | // bogus pid file so status stops reporting it, but never kill a |
| 152 | // process we can't confirm is ours. |
| 153 | RemovePID(root) |
| 154 | } |
| 155 | return err |
| 156 | } |
| 157 | // Clean up PID file |
| 158 | RemovePID(root) |
| 159 | return nil |
| 160 | } |