#!/bin/sh
#
# php-fastcgi - Use PHP as a FastCGI process via nginx.
#
# chkconfig: - 85 15
# description: Use PHP as a FastCGI process via nginx.
# processname: php-fastcgi
# pidfile: /var/run/nginx/php-fastcgi.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

prog=/usr/bin/php-cgi
user=nginx
group=nginx
host=127.0.0.1
port=9000
pidfile=/var/run/nginx/php-fastcgi.pid
numclients=5

start() {
    echo -n $"Starting $prog: "
    daemon /usr/bin/spawn-fcgi -a $host -p $port -u $user -g $group -f $prog -P $pidfile -C $numclients || exit 1
    echo
}

stop() {
    echo -n $"Stopping $prog: "
    killproc -p $pidfile -d 60 $prog || exit 1
    echo
}

restart() {
    stop
    start
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart|reload)
	restart
	;;
    status)
	status -p $pidfile $prog
	;;
    *)
	echo $"Usage: $0 {start|stop|status|restart}"
	exit 2
esac
