I am trying to use start-stop-daemon to start a process that runs in the background. To my knowledge, start-stop-daemon is supposed to prevent a second process from being started if one is already running. The script I am running is rather simple for now:
我正在尝试使用start-stop-daemon来启动在后台运行的进程。据我所知,如果一个进程已经在运行,那么start-stop-daemon应该阻止第二个进程启动。我现在运行的脚本相当简单:
#!/bin/sh
while true; do
date > /home/pi/test/test.txt
sleep 10
done
I am starting the script using start-stop-daemon --start -v -b -m --pidfile /var/run/test.pid --exec /home/pi/test/test.sh
我正在使用start-stop-daemon——start -v -b -m——pidfile /var/run/test.来启动脚本pid - exec /home/pi/test/test.sh
I am able to successfully stop the script using start-stop-daemon --stop -v --pidfile /var/run/test.pid
我可以使用start-stop-daemon—stop -v—pidfile /var/run/test.pid成功地停止脚本
However, if I run the start command twice, it will start two processes, instead of just one that I was expecting. Does the start command check the pid file before starting the process, or is there something else that needs to be done for that to happen?
但是,如果我运行start命令两次,它将启动两个进程,而不是我预期的一个进程。开始命令是否在启动进程之前检查pid文件,或者是否需要做一些其他的事情来实现它?
1 个解决方案
#1
3
The man page of start-stop-daemon contains a special warning on the usage of the --exec option with scripts.
start-stop-daemon的手册页包含了关于使用-exec选项和脚本的特殊警告。
-x, --exec executable
- x,执行可执行文件
Check for processes that are instances of this executable. The executable argument should be an absolute pathname. Note: this might not work as intended with interpreted scripts, as the executable will point to the interpreter.
检查这些可执行文件的实例。可执行参数应该是绝对路径名。注意:对于解释脚本,这可能不能正常工作,因为可执行文件将指向解释器。
When you run a script, the process that is actually launched is the interpreter noted in the shebang line of the script. This confuses the start-stop-daemon utility.
当您运行一个脚本时,实际启动的过程是在脚本的shebang行中注意到的解释器。这将混淆start-stop-daemon实用程序。
BTW, you can use the -t option to debug that kind of issues with start-stop-daemon.
顺便说一下,您可以使用-t选项来调试与start-stop-daemon有关的问题。
#1
3
The man page of start-stop-daemon contains a special warning on the usage of the --exec option with scripts.
start-stop-daemon的手册页包含了关于使用-exec选项和脚本的特殊警告。
-x, --exec executable
- x,执行可执行文件
Check for processes that are instances of this executable. The executable argument should be an absolute pathname. Note: this might not work as intended with interpreted scripts, as the executable will point to the interpreter.
检查这些可执行文件的实例。可执行参数应该是绝对路径名。注意:对于解释脚本,这可能不能正常工作,因为可执行文件将指向解释器。
When you run a script, the process that is actually launched is the interpreter noted in the shebang line of the script. This confuses the start-stop-daemon utility.
当您运行一个脚本时,实际启动的过程是在脚本的shebang行中注意到的解释器。这将混淆start-stop-daemon实用程序。
BTW, you can use the -t option to debug that kind of issues with start-stop-daemon.
顺便说一下,您可以使用-t选项来调试与start-stop-daemon有关的问题。