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.