Example #1
0
// Handle lifecycle events
func handleSignals(srv *falcore.Server) {
	var sig os.Signal
	var sigChan = make(chan os.Signal)
	signal.Notify(sigChan, syscall.SIGHUP, syscall.SIGUSR1, syscall.SIGINT, syscall.SIGTERM, syscall.SIGTSTP)
	pid := syscall.Getpid()
	for {
		sig = <-sigChan
		switch sig {
		case syscall.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 syscall.SIGUSR1:
			// child sends this back to the parent when it's ready to Accept
			fmt.Println(pid, "Received SIGUSR1.  Stopping accept.")
			srv.StopAccepting()
		case syscall.SIGINT:
			fmt.Println(pid, "Received SIGINT.  Shutting down.")
			os.Exit(0)
		case syscall.SIGTERM:
			fmt.Println(pid, "Received SIGTERM.  Terminating.")
			os.Exit(0)
		case syscall.SIGTSTP:
			fmt.Println(pid, "Received SIGTSTP.  Stopping.")
			syscall.Kill(pid, syscall.SIGSTOP)
		default:
			fmt.Println(pid, "Received", sig, ": ignoring")
		}
	}
}