github.com/zhongdalu/gf@v1.0.0/g/net/ghttp/ghttp_server_admin_unix.go (about) 1 // Copyright 2017 gf Author(https://github.com/zhongdalu/gf). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/zhongdalu/gf. 6 7 // +build !windows 8 9 package ghttp 10 11 import ( 12 "os" 13 "os/signal" 14 "syscall" 15 ) 16 17 // 进程信号量监听消息队列 18 var procSignalChan = make(chan os.Signal) 19 20 // 信号量处理 21 func handleProcessSignal() { 22 var sig os.Signal 23 signal.Notify( 24 procSignalChan, 25 syscall.SIGINT, 26 syscall.SIGQUIT, 27 syscall.SIGKILL, 28 syscall.SIGTERM, 29 syscall.SIGUSR1, 30 syscall.SIGUSR2, 31 ) 32 for { 33 sig = <-procSignalChan 34 switch sig { 35 // 进程终止,停止所有子进程运行 36 case syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL, syscall.SIGTERM: 37 shutdownWebServers(sig.String()) 38 return 39 40 // 用户信号,重启服务 41 case syscall.SIGUSR1: 42 restartWebServers(sig.String()) 43 return 44 45 default: 46 } 47 } 48 }