Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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.

share|improve this answer
    
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
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.