After the first reload: "nginx: [error] open() "/var/run/nginx.pid" failed (2: No such file or directory)"

Viewed 5517

Using Salt I applied states that install and run NGINX (1.14.0-0ubuntu1.7) as a service. Service's status is active but systemctl reload nginx keeps failing thus an updated config cannot be applied.

Full logs:

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.
1 Answers

I believe that the main problem in this case is the fact that the NGINX service had been started initially before the needed /etc/nginx/nginx.conf was placed. In my opinion, this order causes NGINX searches the PID file defined in the nginx.conf but the PID location policy was different during the start thus the PID file was not defined in the place expected by the reloading service.

However, service.running watches file: /etc/nginx/nginx.conf. But it is not enough because the first start of the service occurs just after the package installation with the default nginx.conf.

To sum up, the solution is to place /etc/nginx/nginx.conf with different pid directive before the package installation (if the package is installed ensure that all NGINX processes are killed, start the service with the needed nginx.conf OR [be careful, backup configs...] just fully remove the package disabling services and removing configs). In case of Salt Stack put - require_in: pkg: nginx (nginx here is the name of the package installation state) into the state that manages the /etc/nginx/nginx.conf.

Related