Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

start-stop-daemon does not write to nginx.pid file even though the file is present

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.

like image 715
Narendra Rajput Avatar asked Sep 17 '12 11:09

Narendra Rajput


1 Answers

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.

like image 76
Peter Avatar answered Oct 06 '22 13:10

Peter