This may seem to be a repeated question but it is not. I found some articles on it where start-stop-daemon
doesn't create a PID file. But in my case, I have already created the PID file. I execute this command on my server to start Nginx:
/mnt/nginx/logs/nginx.pid
start-stop-daemon --start --quiet --pidfile /mnt/nginx/logs/nginx.pid --exec /usr/local/sbin/nginx
The PID file is already present but still the start-stop-daemon
doesn't write to the file. I even tried to use the --make-pidfile
option but then the start-stop-daemon
writes wrong pid to the file.
The --make-pidfile
option is required. The reason start-stop-daemon
writes the "wrong pid" is that nginx
forks. This is noted in the start-stop-daemon
man page:
-m, --make-pidfile
Used when starting a program that does not create its own pid
file. This option will make start-stop-daemon create the file
referenced with --pidfile and place the pid into it just before
executing the process. Note, the file will not be removed when
stopping the program. NOTE: This feature may not work in all
cases. Most notably when the program being executed forks from
its main process. Because of this, it is usually only useful
when combined with the --background option.
(See the part re forking.)
You'll need to use a different solution, such as getting nginx
to create its own pid file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With