[root@localhost sbin]# ls
1.sh nginx nginx.0 nginx.2 nginx.3.bak nginx.lua nginx.oldnginx
測試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
dom
最後剩下
[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 nginxide
成功測試
測試2:
[root@localhost system]# cat nginx.service
[Unit]
Description=nginx
After=network.targetui
[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=truelua
[Install]
WantedBy=multi-user.targetcode
用systemd forking 方式生成的nginx,使用kill -QUIT cat /usr/local/nginx/logs/nginx.pid.oldbin
命令,
進程會所有退出進程
ab -n1000000 -c10 http://domain.com/ip
總結,還須要去看下forking是怎麼控制進程的?get
'''
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
'''