停止
()
| 216 | |
| 217 | // 停止 |
| 218 | func (this *AppCmd) runStop() { |
| 219 | var pid = this.getPID() |
| 220 | if pid == 0 { |
| 221 | fmt.Println(this.product + " not started yet") |
| 222 | return |
| 223 | } |
| 224 | |
| 225 | // 从systemd中停止 |
| 226 | if runtime.GOOS == "linux" { |
| 227 | systemctl, _ := executils.LookPath("systemctl") |
| 228 | if len(systemctl) > 0 { |
| 229 | go func() { |
| 230 | // 有可能会长时间执行,这里不阻塞进程 |
| 231 | _ = exec.Command(systemctl, "stop", teaconst.SystemdServiceName).Run() |
| 232 | }() |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | // 如果仍在运行,则发送停止指令 |
| 237 | _, _ = this.sock.SendTimeout(&gosock.Command{Code: "stop"}, 1*time.Second) |
| 238 | |
| 239 | fmt.Println(this.product+" stopped ok, pid:", types.String(pid)) |
| 240 | } |
| 241 | |
| 242 | // 重启 |
| 243 | func (this *AppCmd) runRestart() { |
no test coverage detected