Nginx

無法停止 nginx 服務

  • November 11, 2019

我們在 systemd 中執行了 nginx(在埠 8080 上),CentOS 7.7但無法停止它 - 沒有錯誤,它只是繼續執行或重生。

我們已經嘗試過sudo systemctl stopsudo systemctl disable甚至嘗試過,kill但它一直在執行。

Nov 11 13:04:18 myhost systemd[1]: Started The Gateway - Nginx.
[myuser@myhost gateway]$ sudo systemctl stop gateway
[myuser@myhost gateway]$ sudo systemctl status gateway
gateway.service - The Gateway - Nginx
  Loaded: loaded (/usr/lib/systemd/system/gateway.service; enabled; vendor preset: disabled)
  Active: inactive (dead) since Mon 2019-11-11 13:04:18 CET; 6min ago
 Process: 20988 ExecStart=/usr/sbin/nginx -c /prg/nginx/conf/gateway.conf (code=exited, status=0/SUCCESS)
 Process: 20985 ExecStartPre=/usr/sbin/nginx -t -c /prg/nginx/conf/gateway.conf (code=exited, status=0/SUCCESS)
 Process: 20983 ExecStartPre=/usr/bin/rm -f /daten/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 20988 (code=exited, status=0/SUCCESS)
   Tasks: 2
  Memory: 1.6M
  CGroup: /system.slice/gateway.service
          ├─20990 nginx: master process /usr/sbin/nginx -c /prg/nginx/conf/gateway.conf
          └─20991 nginx: worker process

Nov 11 13:04:18 myhost systemd[1]: Starting The Gateway - Nginx...
Nov 11 13:04:18 myhost node-gateway[20985]: nginx: the configuration file /prg/nginx/conf/gateway.conf syntax is ok
Nov 11 13:04:18 myhost node-gateway[20985]: nginx: configuration file /prg/nginx/conf/gateway.conf test is successful
Nov 11 13:04:18 myhost systemd[1]: Started The Gateway - Nginx.

禁用並停止

[myuser@myhost gateway]$ sudo systemctl disable gateway
Removed symlink /etc/systemd/system/multi-user.target.wants/gateway.service.
[myuser@myhost gateway]$ sudo systemctl stop gateway

仍在執行

[myuser@myhost gateway]$ sudo systemctl status gateway
gateway.service - The Gateway - Nginx
  Loaded: loaded (/usr/lib/systemd/system/gateway.service; disabled; vendor preset: disabled)
  Active: inactive (dead) since Mon 2019-11-11 13:04:18 CET; 6min ago
Main PID: 20988 (code=exited, status=0/SUCCESS)
  CGroup: /system.slice/gateway.service
          ├─20990 nginx: master process /usr/sbin/nginx -c /prg/nginx/conf/gateway.conf
          └─20991 nginx: worker process

Nov 11 13:04:18 myhost systemd[1]: Starting The Gateway - Nginx...
Nov 11 13:04:18 myhost node-gateway[20985]: nginx: the configuration file /prg/nginx/conf/gateway.conf syntax is ok
Nov 11 13:04:18 myhost node-gateway[20985]: nginx: configuration file /prg/nginx/conf/gateway.conf test is successful
Nov 11 13:04:18 myhost systemd[1]: Started The Gateway - Nginx.
[myuser@myhost gateway]$ ps -auxf | grep nginx
myuser    21846  0.0  0.0 112684   696 pts/0    S+   13:11   0:00  |           \_ grep --color=auto nginx
root      20990  0.0  0.0  59080  1388 ?        Ss   13:04   0:00 nginx: master process /usr/sbin/nginx -c /prg/nginx/conf/gateway.conf
nginx     20991  0.0  0.0  61272  2708 ?        S    13:04   0:00  \_ nginx: worker process
[myuser@myhost gateway]$ sudo lsof -i -P -n | grep 8080
node       1313              root   20u  IPv4 429747      0t0  TCP 127.0.0.1:51580->127.0.0.1:8080 (ESTABLISHED)
node       1313              root   21u  IPv4 432203      0t0  TCP 127.0.0.1:51640->127.0.0.1:8080 (ESTABLISHED)
node       1316 serviceuser   19u  IPv4 332198      0t0  TCP 172.25.24.45:57328->172.25.24.20:8080 (ESTABLISHED)
node       1316 serviceuser   21u  IPv4 318233      0t0  TCP 172.25.24.45:57260->172.25.24.20:8080 (ESTABLISHED)
nginx     20990              root    6u  IPv4 430360      0t0  TCP *:8080 (LISTEN)
nginx     20991             nginx    3u  IPv4 430473      0t0  TCP 127.0.0.1:8080->127.0.0.1:51580 (ESTABLISHED)
nginx     20991             nginx    6u  IPv4 430360      0t0  TCP *:8080 (LISTEN)
nginx     20991             nginx   25u  IPv4 432204      0t0  TCP 127.0.0.1:8080->127.0.0.1:51640 (ESTABLISHED)
Active: inactive (dead) since Mon 2019-11-11 13:04:18 CET; 6min ago

對我來說它看起來不活躍(=死了,停止了,不管你怎麼稱呼它)?

編輯:似乎這個過程可能仍然存在:

root      20990  0.0  0.0  59080  1388 ?        Ss   13:04   0:00 nginx: master process /usr/sbin/nginx -c /prg/nginx/conf/gateway.con

您可以嘗試使用 kill 命令手動殺死它,如果 SIGTERM 不起作用,請嘗試 SIGKILL

kill -SIGTERM <process id, 20990 in this case>

引用自:https://serverfault.com/questions/991354