在平滑升级nginx的时候,如果不给出nginx程序的全路径的话,会出现USR2信号没起作用的情况
具体如下
验证
用nginx命令直接启动,不给全路径
[root@vm2 ~]# ll /usr/local/nginx/sbin/
total 30556
-rwxr-xr-x 1 nginx nginx 5175248 Feb 7 11:32 nginx
-rwxr-xr-x 1 nginx nginx 7934392 Feb 6 20:27 nginx.old
-rwxr-xr-x 1 nginx nginx 7934392 Feb 7 11:09 nginx.old2
-rwxr-xr-x 1 nginx nginx 5175248 Feb 7 11:32 nginx.old3
-rwxr-xr-x 1 nginx nginx 5055968 Feb 7 11:39 nginx.old4
[root@vm2 ~]# ll /usr/sbin/nginx
lrwxrwxrwx 1 root root 27 Feb 6 20:31 /usr/sbin/nginx -> /usr/local/nginx/sbin/nginx
[root@vm2 ~]# nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
# 启动nginx,不给全路径
[root@vm2 ~]# nginx
[root@vm2 ~]# pstree -p | grep nginx
|-nginx(12096)---nginx(12097)
[root@vm2 ~]# cat /usr/local/nginx/logs/nginx.pid
12096
# 升级二进制
[root@vm2 ~]# rm -f /usr/local/nginx/sbin/nginx
[root@vm2 ~]# cp -p /usr/local/nginx/sbin/nginx.old4 /usr/local/nginx/sbin/nginx
[root@vm2 ~]# nginx -V
nginx version: nginx/1.21.6
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
# 发送USR2。没有新的,master
[root@vm2 ~]# kill -USR2 12096
[root@vm2 ~]# ps -ef | grep nginx
root 12096 1 0 12:10 ? 00:00:00 nginx: master process nginx
nginx 12097 12096 0 12:10 ? 00:00:00 nginx: worker process
root 12109 1124 0 12:12 pts/1 00:00:00 grep --color=auto nginx
[root@vm2 ~]#
非软连接的全路径
[root@vm2 ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
# 用不是软连接的全路径
[root@vm2 ~]# /usr/local/nginx/sbin/nginx
[root@vm2 ~]# ps -ef | grep nginx
root 12119 1 0 12:15 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12120 12119 0 12:15 ? 00:00:00 nginx: worker process
root 12122 1124 0 12:16 pts/1 00:00:00 grep --color=auto nginx
[root@vm2 ~]# cat /usr/local/nginx/logs/nginx.pid
12119
# 换新程序
[root@vm2 ~]# rm -f /usr/local/nginx/sbin/nginx
[root@vm2 ~]# cp -p /usr/local/nginx/sbin/nginx.old4 /usr/local/nginx/sbin/nginx
[root@vm2 ~]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.21.6
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
# 发送USR2,有新master进程
[root@vm2 ~]# kill -USR2 12119
[root@vm2 ~]# ps -ef | grep nginx
root 12119 1 0 12:15 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12120 12119 0 12:15 ? 00:00:00 nginx: worker process
root 12127 12119 0 12:17 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx 12128 12127 0 12:17 ? 00:00:00 nginx: worker process
root 12130 1124 0 12:17 pts/1 00:00:00 grep --color=auto nginx
全路径的软连接
[root@vm2 ~]# which nginx
/usr/sbin/nginx
[root@vm2 ~]# ll /usr/sbin/nginx
lrwxrwxrwx 1 root root 27 Feb 6 20:31 /usr/sbin/nginx -> /usr/local/nginx/sbin/nginx
[root@vm2 ~]# /usr/sbin/nginx -V
nginx version: nginx/1.20.2
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC)
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx
# 使用全路径软连接
[root@vm2 ~]# /usr/sbin/nginx
[root@vm2 ~]# pstree -p | grep nginx
|-nginx(12147)---nginx(12148)
[root@vm2 ~]# ps -ef | grep nginx
root 12147 1 0 12:22 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 12148 12147 0 12:22 ? 00:00:00 nginx: worker process
root 12152 1124 0 12:22 pts/1 00:00:00 grep --color=auto nginx
# 换新程序
[root@vm2 ~]# rm -f /usr/local/nginx/sbin/nginx
[root@vm2 ~]# cp -p /usr/local/nginx/sbin/nginx.old4 /usr/local/nginx/sbin/nginx
# 发送USR2,有新的master进程
[root@vm2 ~]# kill -USR2 12147
[root@vm2 ~]# ps -ef | grep nginx
root 12147 1 0 12:22 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 12148 12147 0 12:22 ? 00:00:00 nginx: worker process
root 12155 12147 0 12:23 ? 00:00:00 nginx: master process /usr/sbin/nginx
nginx 12156 12155 0 12:23 ? 00:00:00 nginx: worker process
root 12158 1124 0 12:23 pts/1 00:00:00 grep --color=auto nginx