()
| 17 | } |
| 18 | |
| 19 | func kill() { |
| 20 | initDaemon() |
| 21 | if pid == -1 { |
| 22 | log.Info("Seems not have been started. Try use `openlist start` to start server.") |
| 23 | return |
| 24 | } |
| 25 | process, err := os.FindProcess(pid) |
| 26 | if err != nil { |
| 27 | log.Errorf("failed to find process by pid: %d, reason: %v", pid, process) |
| 28 | return |
| 29 | } |
| 30 | err = process.Kill() |
| 31 | if err != nil { |
| 32 | log.Errorf("failed to kill process %d: %v", pid, err) |
| 33 | } else { |
| 34 | log.Info("killed process: ", pid) |
| 35 | } |
| 36 | err = os.Remove(pidFile) |
| 37 | if err != nil { |
| 38 | log.Errorf("failed to remove pid file") |
| 39 | } |
| 40 | pid = -1 |
| 41 | } |
| 42 | |
| 43 | func init() { |
| 44 | RootCmd.AddCommand(KillCmd) |
no test coverage detected