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
/var/log/syslog
, or some other file in/var/log
?