I'm running Linux Mint 19.2 Tina, which should be equivalent to Ubuntu 18.04.
When I issue the command sudo systemctl stop nginx.service
then systemctl start nginx.service
I frequently get the error
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
and
nginx: [error] open() "/run/nginx.pid" failed (2: No such file or directory)
I'm not able to restart nginx with the systemctl command, but checking with ps aux | grep nginx
shows that nginx is running. Checking with sudo ss -lnp | grep nginx
shows that the process is bound to port 80 and port 443. But /run/nginx.pid
does not exist.
I can kill this process manually with sudo kill $PID_OF_MASTER_NGINX_PROCESS
but the normal control commands don't work.
I finally noticed something that helped solve this. When I examined the output of
ps aux | grep nginx
after starting with systemctl, I saw something like the following...But after the process autostarted on me I saw the following...
Notice that the command line options for the master process were a bit different. In the systemctl case the command line options included
-g daemon on; master_process on;
but in the other case they included-c /etc/nginx/nginx.conf
. Two different processes were trying to control nginx. The second one would notice that it wasn't running and try to autostart it.The command line with
-g daemon on; master_process on;
was reflected in the systemd file/lib/systemd/system/nginx.service
. The other command line was reflected in/etc/init.d/nginx
. I guessed that both systemd and the old init system were trying to run nginx.I ran the command
sudo update-rc.d -f nginx disable
which removed the nginx start scripts from all the run level directories for the old init system. Now nginx starts and stops properly with the systemctl commands.