Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 writing an lsb init script (admittedly something I've never done from scratch) that launches a php script that daemonizes itself. The php script starts off like so:

#!/usr/bin/env php
/* do some stuff */

It's then started like so in the init script:

# first line is args to start-stop-daemon, second line is args to php-script
start-stop-daemon --start --exec /path/to/executable/php-script.php \
  -- --daemon --pid-file=$PIDFILE --other-php-script-args

The --daemon flag causes the php script to detach & run as a daemon itself, rather than relying on start-stop-daemon to detach it.

This is how it's (trying to) stop it in the init script:

start-stop-daemon --stop --oknodo --exec /path/to/executable/php-script.php \
  --pidfile $PIDFILE

The problem is, when I try to stop via the init script, it gives me this:

$ sudo /etc/init.d/my-lsb-init-script stop
 * Stopping My Project
No /path/to/executable/php-script.php found running; none killed.

A quick peek at ps tells me that, even though the php script itself is executable, its running as php <script> rather than the script name itself, which is keeping start-stop-daemon from seeing it. The PID file is even being generated, but it seems to ignore it and try to find+kill by process name instead.

$ ps ax | grep '/path/to/executable/php-script.php'
 2505 pts/1    S      0:01 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/ --other-php-script-args
 2507 pts/1    S      0:00 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/ --other-php-script-args
 2508 pts/1    S      0:00 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/ --other-php-script-args
 2509 pts/1    S      0:00 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/ --other-php-script-args
 2518 pts/1    S      0:01 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/ --other-php-script-args
$ cat /var/run/blah/

Am I completely misunderstanding something here? Or is there an easy way to work around this?

share|improve this question
up vote 6 down vote accepted

Correct stop:

start-stop-daemon --stop --oknodo --pidfile $PIDFILE
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.