centos7 nginx平滑升级 systemd

[root@localhost sbin]# ls
1.sh nginx nginx.0 nginx.2 nginx.3.bak nginx.lua nginx.old

测试1:
cat 1.sh
yes|cp -r nginx.0 nginx
#service nginx start
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
[ -f nginx.old ] && rm -rf nginx.old
mv nginx nginx.old
yes|cp -r nginx.2 nginx
sleep 60
kill -USR2 cat /usr/local/nginx/logs/nginx.pid
kill -WINCH cat /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT cat /usr/local/nginx/logs/nginx.pid.oldbin

最后剩下
[root@localhost nginx]# ps -ef|grep nginx
root 30530 1 0 16:08 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
root 30589 30530 0 16:09 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx 30590 30589 0 16:09 ? 00:00:00 nginx: worker process
root 30619 30360 0 16:10 pts/6 00:00:00 grep --color=auto nginx
[root@localhost nginx]# kill -QUIT cat /usr/local/nginx/logs/nginx.pid.oldbin
[root@localhost nginx]# ps -ef|grep nginx
root 30589 1 0 16:09 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nginx 30590 30589 0 16:09 ? 00:00:00 nginx: worker process
root 30683 30360 0 16:11 pts/6 00:00:00 grep --color=auto nginx

成功

测试2:
[root@localhost system]# cat nginx.service
[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

用systemd forking 方式生成的nginx,使用kill -QUIT cat /usr/local/nginx/logs/nginx.pid.oldbin命令,
进程会全部退出

ab -n1000000 -c10 http://domain.com/

总结,还需要去看下forking是怎么控制进程的?

'''
strace kill -USR2 cat /usr/local/nginx/logs/nginx.pid
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin

kill -WINCH cat /usr/local/nginx/logs/nginx.pid.oldbin

yes|cp -r nginx.0 nginx
service nginx start
[ -f nginx.old ] && rm -rf nginx.old
mv nginx nginx.old
yes|cp -r nginx.2 nginx
sleep 1
kill -USR2 cat /usr/local/nginx/logs/nginx.pid

'''

转载于:https://blog.51cto.com/szgb17/2333498

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值