即使文件存在,start-stop-daemon也不会写入nginx.pid文件

Nar*_*put 6 nginx start-stop-daemon

这似乎是一个重复的问题,但事实并非如此.我在其上发现了一些start-stop-daemon没有创建PID文件的文章.但就我而言,我已经创建了PID文件.我在服务器上执行此命令以启动Nginx:

/mnt/nginx/logs/nginx.pid
start-stop-daemon --start --quiet --pidfile /mnt/nginx/logs/nginx.pid --exec /usr/local/sbin/nginx
Run Code Online (Sandbox Code Playgroud)

PID文件已存在但仍未start-stop-daemon写入文件.我甚至尝试使用该--make-pidfile选项,但随后start-stop-daemon写入错误的pid到文件.

Pet*_*ter 7

--make-pidfile选项是必需的.start-stop-daemon写"错误的pid" 的原因是nginx叉子.这在start-stop-daemon手册页中注明:

   -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.
Run Code Online (Sandbox Code Playgroud)

(参见重新分叉的部分.)

您需要使用其他解决方案,例如nginx创建自己的pid文件.