nginx的优雅退出
-s signal Send signal to the master process. The argument signal can be
one of: stop, quit, reopen, reload.
The following table shows the corresponding system signals.
stop SIGTERM
quit SIGQUIT
reopen SIGUSR1
reload SIGHUP
其中
stop — 快速关闭
quit — 优雅退出,执行完当前的请求后退出
reload — 重新加载配置文件
reopen — 重新打开日志文件
kill -USR2 旧版程序的主进程号或进程文件名
此时旧的Nginx主进程将会把自己的进程文件改名为.oldbin,然后执行新版 Nginx。新旧Nginx会同市运行,共同处理请求。
使用kubernetes Lifecycle Hooks优雅退出nginx kind: Deploymentmetadata: name: nginx-demo namespace: scm labels: app: nginx-demospec: replicas: 1 template: metadata: labels: app: nginx-demo spec: containers: - name: nginx-demo image: library/nginx-demo imagePullPolicy: IfNotPresent lifecycle: preStop: exec: # nginx -s quit gracefully terminate while SIGTERM triggers a quick exit command: ["/usr/local/openresty/nginx/sbin/nginx","-s","quit"] env: - name: PROFILE value: "test" ports: - name: http containerPort: 8080 题外 如何优雅地关闭java应用 command: ["/bin/bash", "-c", "PID=`pidof java` && kill -SIGTERM $PID && while ps -p $PID > /dev/null; do sleep 1; done;"] doc
转载
https://segmentfault.com/a/1190000008233992
https://kubernetes.feisky.xyz/practice/app-ha
请登录之后再进行评论