这似乎是一个重复的问题,但事实并非如此。我发现了一些文章,其中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
PID文件已存在,但start-stop-daemon
仍未写入文件。我甚至尝试使用--make-pidfile
选项,但start-stop-daemon
将错误的pid写入文件。
答案 0 :(得分: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.
(参见重新分叉的部分。)
您需要使用其他解决方案,例如让nginx
创建自己的pid文件。