概述

项目中安装部署最新nginx后由开发修改对应配置文件。在启动和重新启动nginx发现systemctl命令卡住无输出,在终止命令后发现服务实际已经运行。

解决办法

由于Nginx为yum安装,默认的pid文件路径是/run/nginx.pid,开发修改了nginx中的默认pid文件路径。导致systemctl命令无法读取到pid内容以至于夯住。

[root@localhost ~]# vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/run/nginx.pid
# Nginx will fail to start if /run/nginx.pid already exists but has the wrong
# SELinux context. This might happen when running `nginx -t` from the cmdline.
# https://bugzilla.redhat.com/show_bug.cgi?id=1268621
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/usr/sbin/nginx -s reload
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true

[Install]
WantedBy=multi-user.target

修改PIDFile=路径为Nginx配置文件中的pid路径即可解决。

END

本文标题:systemctl管理nginx启动或重新启动卡住问题处理

本文作者:宇宙最帅的男人

本文链接:https://lolicp.com/nginx/202127374.html

版权声明:转载或者引用本文内容请注明来源及原作者,本文著作权归作者 (宇宙最帅的男人) 所有。

除非另有说明,本作品采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议

最后修改:2021 年 12 月 27 日
如果觉得我的文章对你有用,请随意赞赏