Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
<?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.
   ...done.

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/blah.pid --other-php-script-args
 2507 pts/1    S      0:00 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/blah.pid --other-php-script-args
 2508 pts/1    S      0:00 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/blah.pid --other-php-script-args
 2509 pts/1    S      0:00 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/blah.pid --other-php-script-args
 2518 pts/1    S      0:01 php /path/to/executable/php-script.php --daemon --pid-file /var/run/blah/blah.pid --other-php-script-args
$ cat /var/run/blah/blah.pid
2518

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

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

Correct stop:

start-stop-daemon --stop --oknodo --pidfile $PIDFILE
share|improve this answer
add comment

Your Answer

 
discard

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.