0

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.

1 Answer 1

1

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

$ ps aux | grep nginx
root     30369  0.0  0.0 142168  2004 ?        Ss   21:31   0:00 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
www-data 30370  0.0  0.1 144464  6840 ?        S    21:31   0:00 nginx: worker process
www-data 30371  0.0  0.1 144464  6840 ?        S    21:31   0:00 nginx: worker process
www-data 30372  0.0  0.1 144464  6840 ?        S    21:31   0:00 nginx: worker process
www-data 30373  0.0  0.1 144464  6840 ?        S    21:31   0:00 nginx: worker process

But after the process autostarted on me I saw the following...

$ ps aux | grep nginx
root     29591  0.0  0.1 142732  9440 ?        Ss   21:25   0:00 nginx: master process nginx -c /etc/nginx/nginx.conf
www-data 29616  0.0  0.1 145028  7248 ?        S    21:25   0:00 nginx: worker process
www-data 29617  0.0  0.1 145028  7248 ?        S    21:25   0:00 nginx: worker process
www-data 29618  0.0  0.1 145028  7248 ?        S    21:25   0:00 nginx: worker process
www-data 29619  0.0  0.1 145028  7248 ?        S    21:25   0:00 nginx: worker process

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.

1
  • Thanks ! I also noticed the params but didn't knew what to do next. I also had to add --standalone because nginx plugin in certbot was running somehow. See this topic: unix.stackexchange.com/questions/702133/…
    – Alcalyn
    Commented Sep 11, 2023 at 12:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .