linux 信号
当系统热重启时,服务不间断,系统内存中数据需要全部写入到数据库。
gracehttp
包
func (srv *Server) handleSignals() { var sig os.Signal signal.Notify( srv.signalChan, syscall.SIGTERM, syscall.SIGUSR2, ) for { sig = <-srv.signalChan switch sig { case syscall.SIGTERM: srv.logf("received SIGTERM, graceful shutting down HTTP server.") srv.shutdownHTTPServer() case syscall.SIGUSR2: srv.logf("received SIGUSR2, graceful restarting HTTP server.") if pid, err := srv.startNewProcess(); err != nil { srv.logf("start new process failed: %v, continue serving.", err) } else { srv.logf("start new process successed, the new pid is %d.", pid) srv.shutdownHTTPServer() } default: } } }
监听Linux信号,收到重启信号后,等待任务全部处理完再退出进程(因为使用了第三方包,它也在监听信号,它会在没有http请求后终止服务,所以这个不可行)
共享内存。这样多个进程都可以读取数据。
相关推荐
YoungLinux 2020-10-08
wpfeitian 2020-10-05
ChasingChasing 2020-08-31
pointfish 2020-07-18
hnllei 2020-06-25
LUOPING0 2020-06-17
RayCongLiang 2020-06-01
哥哥的CSDN集 2020-05-06
xiaohouye 2020-05-02
河的第三条岸 2020-04-13
wangrui0 2019-12-26
secondid 2019-12-06
xiaohouye 2019-11-13
plcjianghao 2011-04-12
andyzhaojianhui 2011-04-04
farmanlinuxer 2011-04-01
sprintwind 2011-03-23
Kshine0 2011-03-11
揅笑晏晏 2011-02-12