コード例 #1
0
ファイル: hot_restart.go プロジェクト: repos-go/falcore
// Handle lifecycle events
func handleSignals(srv *falcore.Server) {
	var sig os.Signal
	pid := syscall.Getpid()
	for {
		sig = <-signal.Incoming
		if usig, ok := sig.(os.UnixSignal); ok {
			switch usig {
			case os.SIGHUP:
				// send this to the paraent process to initiate the restart
				fmt.Println(pid, "Received SIGHUP.  forking.")
				cpid, err := forker(srv)
				fmt.Println(pid, "Forked pid:", cpid, "errno:", err)
			case os.SIGUSR1:
				// child sends this back to the parent when it's ready to Accept
				fmt.Println(pid, "Received SIGUSR1.  Stopping accept.")
				srv.StopAccepting()
			case os.SIGINT:
				fmt.Println(pid, "Received SIGINT.  Shutting down.")
				os.Exit(0)
			case os.SIGTERM:
				fmt.Println(pid, "Received SIGTERM.  Terminating.")
				os.Exit(0)
			case os.SIGTSTP:
				fmt.Println(pid, "Received SIGTSTP.  Stopping.")
				syscall.Kill(pid, syscall.SIGSTOP)
			default:
				fmt.Println(pid, "Received", sig, ": ignoring")
			}
		}
	}
}