engineAL
engineAL

Reputation: 394

start-stop-daemon starting multiple processes

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:

#!/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

I am able to successfully stop the script using 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?

Upvotes: 4

Views: 4000

Answers (1)

Leon
Leon

Reputation: 32444

The man page of start-stop-daemon contains a special warning on the usage of the --exec option with scripts.

-x, --exec executable

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.

BTW, you can use the -t option to debug that kind of issues with start-stop-daemon.

Upvotes: 5

Related Questions