Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm starting a python script that i've created using start-stop-daemon. It works perfectly in all cases, except when I've forgotten that I've already started it. It creates a new process, but is unable to kill the old processes automatically.

Here's the complete script:


# path to app

# path to paster bin

# startup args
#DAEMON_OPTS=" serve --log-file <my logfile> --server-name=main production.ini"

# script name

# app name

# pylons user


############### END EDIT ME ##################

test -x $DAEMON || exit 0

set -e

case "$1" in
        echo -n "Starting $DESC: "
    start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE  --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        echo -n "Stopping $DESC: "
        start-stop-daemon --stop --pidfile $PID_FILE
        echo "$NAME."

        echo -n "Restarting $DESC: "
        start-stop-daemon --stop --pidfile $PID_FILE
        sleep 1
        start-stop-daemon -d $APP_PATH -c $RUN_AS --start --background --pidfile $PID_FILE  --make-pidfile --exec $DAEMON -- $DAEMON_OPTS
        echo "$NAME."
        echo "Usage: $N {start|stop|restart|force-reload}" >&2
        exit 1

exit 0

Is there a way to have it check? I've tried the -S switch with no luck so far.


share|improve this question
Can you post the complete command? – Khaled Dec 5 '11 at 20:38
done. i'm thinking of adding in error-checking outside of start-stop-daemon, but it'd be great if it knew on its own. – Larry G. Wapnitsky Dec 5 '11 at 20:55
I wound up adding a bit of code to the script that checks for running processes with (or whatever I rename it to eventually) via ps and grep prior to starting the daemon. If the processes exist, the service does not attempt to start. – Larry G. Wapnitsky Dec 6 '11 at 12:42

$PID_FILE will contain the process id only of the latest instance you started, so only this instance will be killed.

Something you could do to resolve this, is to grep the PIDs of the running instances of your daemon and terminate them using kill.

...or just check if there's another running instance of your script, before calling start-stop-daemon.

What is being spawned and ran is the Python interpreter, but start-stop-daemon checks for a process named and obviously can't find it.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.