0

I'm new to init scripts, but the one I'm using I've copied almost verbatim (I did have to change a few things around from the source I found to work with Fedora). The daemon initializes fastcgi just fine, which was a great victory. However, the init script itself never finishes running, and never returns [ok], even though the program is initialized. It just hangs at "Starting PHP FastCGI" with a blinking cursor. I can't ^C out of it, either.

The init script is below. This is a Fedora14 server.

#!/bin/sh
#chkconfig 3 85 15
#processname: php-fcgi
 . /etc/rc.d/init.d/functions

php_cgi="/usr/bin/php-cgi"
prog=$(basename $php_cgi)
bind=/tmp/php.socket

php_fcgi_children=15
php_fcgi_max_requests=1000

user=root
php_cgi_args="- USER=$user PATH=/usr/bin PHP_FCGI_CHILDREN=$php_fcgi_children PHP_FCGI_MAX_REQUESTS=$php_fcgi_max_requests $php_cgi -b $bind"
RETVAL=0
start() {
    echo -n "Starting PHP FastCGI: "
    daemon /usr/bin/env $php_cgi_args
    RETVAL=$?
    echo "$prog."
}

stop() {
    echo -n "Stopping PHP FastCGI: "
    killall -q -w -u $user $php_cgi
    RETVAL=$?
    echo "$prog."
}

case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart)
        stop
        start
    ;;
    *)
    echo "Usage: php-fcgi {start|stop|restart}"
    exit 1
    ;;
esac
exit $RETVAL
0

Sounds like the php-fcgi process doesn't daemonize by default, which means it will stay in the foreground and block progress just like you have observed. Most applications intended to run as daemons have an option that will cause it to daemonize (in short; run as a background process). If the php-fcgi process does not have such an option you will have to explicitly run it in the background instead, replace the deamon line with something like this:

/usr/bin/env $php_cgi_args >/dev/null 2>&1 &

If the process does any kind of direct logging to standard out or error that you want to be able to look at replace /dev/null above with the name of a log file.

  • Gotcha. I checked the help for php-cgi and it does not have a daemonizing option. I was not aware what 2>&1 & did before; thank you! – Tom Thorogood Oct 6 '11 at 11:08
  • Funny story: I forgot to ever change this, and my server had to be reprovisioned because it couldn't start up. D'oh! I made sure to make that the first thing to do after the repro. Thanks again for that! – Tom Thorogood Oct 14 '11 at 19:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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