[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命令,
进程会全部退出
总结,还需要去看下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
'''