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 have nginx on my server (Ubuntu 11.10). i have created the script below in /etc/init.d/php5cgi to start/stop/restart php5-cgi. the problem is that php5-cgi dies from time to another which makes my website (nginx) giving 502 Bad Gateway (and i dont know why!! it would be highly appreciated if somebody tells us why php5-cgi dies like this).

now, how can i tell my server to keep this process alive forever, in other words to restart it automatically in case it has been stopped (i though in making a shell script and cron job to keep checking, but this means that the website might go down for a minute [from cron to another] and this is not an option for us :( ).

any idea about the reason behind stopping php5cgi very frequently or how to keep it alive forever is highly appreciated.

My /etc/init.d/php5cgi is

COMMAND=/usr/bin/spawn-fcgi
NAME=php5-cgi
ADDRESS=127.0.0.1
PORT=9000
USER=www-data
GROUP=www-data
PHPCGI=/usr/bin/php5-cgi
KILL=/bin/kill

case "$1" in
    start)
        start-stop-daemon --start \
                --exec $COMMAND -- -a $ADDRESS -p $PORT \
                -u $USER -g $GROUP -f $PHPCGI -P /var/run/$NAME.pid|| true
        echo -n "$NAME started with pid "
        cat /var/run/$NAME.pid
        echo
  ;;
    stop)
        if [ -e /var/run/$NAME.pid ]
        then
                $KILL `cat /var/run/$NAME.pid`
                rm /var/run/$NAME.pid
                echo "$NAME stopped"
        else
                echo "$NAME is not running, no pid file in /var/run/"
        fi
  ;;
    restart)
        $0 stop
        $0 start
  ;;
    *)
      echo "Usage: $0 {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL
share|improve this question
    
Are there any log messages from PHP in /var/log/syslog, or some other file in /var/log? –  mgorven May 1 '12 at 21:49
    
If you don't have a specific reason for using php5-cgi, perhaps consider using php5-fpm - it is usually regarded as a superior process manager, and in addition to its other advantages, you might get better stability from it. (It is in the Oneiric repository, so it should be a fairly easy switch actually). –  cyberx86 May 2 '12 at 0:28
    
nothing in the error log :( and my php version is 5.2.10.dfsg.1-2ubuntu6 . there is no fpm package for it, i have tried php5-fpm_5.2.10.dfsg.1-2ubuntu6.4+ppa1_amd64.deb but it didn't work (dpkg: error processing php5-fpm (--install): dependency problems - leaving unconfigured) –  Alaa Alomari May 2 '12 at 7:24

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.