使用 Salt 我应用了将 NGINX (1.14.0-0ubuntu1.7) 作为服务安装和运行的状态。服务的状态处于活动状态,但
systemctl reload nginx
不断失败,因此无法应用更新的配置。
完整日志:
systemd[1]: nginx.service: Can't open PID file /run/nginx.pid (yet?) after reload: No such file or directory
systemd[1]: Reloaded A high performance web server and a reverse proxy server.
systemd[1]: Reloading A high performance web server and a reverse proxy server.
nginx[18095]: nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: Reload failed for A high performance web server and a reverse proxy server.
systemd[1]: Reloading A high performance web server and a reverse proxy server.
nginx[1209]: nginx: [error] invalid PID number "" in "/var/run/nginx.pid"
systemd[1]: nginx.service: Control process exited, code=exited status=1
systemd[1]: Reload failed for A high performance web server and a reverse proxy server.
我认为这种情况下的主要问题是 NGINX 服务在放置所需的
/etc/nginx/nginx.conf
之前就已经启动了。在我看来,这个顺序导致 NGINX 搜索 nginx.conf 中定义的 PID 文件,但 PID 位置策略在启动期间不同,因此 PID 文件没有定义在重新加载服务期望的位置。
但是,service.running 会监视
file: /etc/nginx/nginx.conf
。但这还不够,因为服务的首次启动发生在默认的软件包安装之后 nginx.conf
。
总而言之,解决方案是在软件包安装之前将
/etc/nginx/nginx.conf
与不同的 pid
指令一起放置(如果安装了软件包,请确保杀死所有 NGINX 进程,使用所需的 nginx.conf
启动服务或 [小心,备份配置...]只需完全删除禁用服务并删除配置的软件包)。如果是 Salt Stack,请将 - require_in: pkg: nginx
(这里的 nginx
是软件包安装状态的名称)放入管理 /etc/nginx/nginx.conf
的状态。
我通过重新启动 nginx 而不是重新加载解决了这个问题:
service nginx restart
service nginx status
此后,重新加载也工作正常,并且 pid 号存储在
/var/run/nginx.pid