You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
868 B
868 B
Server graceful restart with Go
安装并运行服务器(打开终端运行一下命令)
$ git clone
$ go mod tidy
$ go run build //不打包第二次以后无法正常重启,会报 Fail to fork1 no such file or directory
$ go-graceful-restart-example
2014/12/14 20:26:42 [Server - 4301] Listen on [::]:12345
[...]
测试客户端(新开一个终端)
$ cd /client
$ go run pong.go
优雅重启服务(再开一个终端)
# 服务器pid包含在其日志中,例如:[Server - 1204933] , 1204933即是当前pid
$ go run build //修改服务端代码后重新打包,再运行才能看到效果
$ kill -HUP <server pid>
延时停止服务
让当前请求等待10秒后强制完成,并停止服务。
$ kill -TERM <server pid>