2019-02-02 16:18:25 +08:00
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-05-13 00:17:12 +08:00
|
|
|
//
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-05-13 00:17:12 +08:00
|
|
|
|
|
|
|
// +build !windows
|
|
|
|
|
|
|
|
package ghttp
|
|
|
|
|
|
|
|
import (
|
2020-04-13 23:44:43 +08:00
|
|
|
"github.com/gogf/gf/internal/intlog"
|
2019-06-19 09:06:52 +08:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
2018-05-13 00:17:12 +08:00
|
|
|
)
|
|
|
|
|
2018-06-01 00:11:45 +08:00
|
|
|
// 进程信号量监听消息队列
|
|
|
|
var procSignalChan = make(chan os.Signal)
|
|
|
|
|
2018-05-13 00:17:12 +08:00
|
|
|
// 信号量处理
|
|
|
|
func handleProcessSignal() {
|
2019-06-19 09:06:52 +08:00
|
|
|
var sig os.Signal
|
|
|
|
signal.Notify(
|
|
|
|
procSignalChan,
|
|
|
|
syscall.SIGINT,
|
|
|
|
syscall.SIGQUIT,
|
|
|
|
syscall.SIGKILL,
|
|
|
|
syscall.SIGTERM,
|
2020-04-13 23:44:43 +08:00
|
|
|
syscall.SIGABRT,
|
2019-06-19 09:06:52 +08:00
|
|
|
syscall.SIGUSR1,
|
|
|
|
syscall.SIGUSR2,
|
|
|
|
)
|
|
|
|
for {
|
|
|
|
sig = <-procSignalChan
|
2020-04-13 23:44:43 +08:00
|
|
|
intlog.Printf(`signal received: %s`, sig.String())
|
2019-06-19 09:06:52 +08:00
|
|
|
switch sig {
|
|
|
|
// 进程终止,停止所有子进程运行
|
2020-04-13 23:44:43 +08:00
|
|
|
case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGTERM, syscall.SIGABRT:
|
2019-06-19 09:06:52 +08:00
|
|
|
shutdownWebServers(sig.String())
|
|
|
|
return
|
2018-06-01 00:11:45 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
// 用户信号,重启服务
|
|
|
|
case syscall.SIGUSR1:
|
|
|
|
restartWebServers(sig.String())
|
|
|
|
return
|
2018-05-13 00:17:12 +08:00
|
|
|
|
2019-06-19 09:06:52 +08:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|