#!/bin/bash # fastcgi script for php5 # chkconfig: - 85 15 # description: fastcgi daemon for php5 # . /etc/rc.d/init.d/functions prog="PHP5-FastCGI" pid_file="/tmp/php-fcgi.pid" user="httpd" group="httpd" threads=10 php_file="/usr/local/php/bin/php-cgi" spawn_file="/usr/local/nginx/sbin/spawn-fcgi" address="127.0.0.1" port="19000" running="0" chk_running(){ if [ -f "$pid_file" ]; then running="1" export running fi } start() { if [ -f "$pid_file" ]; then action $"Startting $prog: " /bin/false echo "$prog is running ..." exit 1 fi $spawn_file -f $php_file -a $address -p $port -P $pid_file -u $user -g $group -C $threads >/dev/null chk_running if [ -f "$pid_file" ]; then action $"Starting $prog: " /bin/true else action $"Starting $prog: " /bin/false echo "Some unexcepted error occupied ..." fi } stop(){ if [ -f "$pid_file" ]; then pid=`cat "$pid_file"` if kill -0 $pid 2>/dev/null; then kill $pid rm -rf $pid_file action $"Stopping $prog: " /bin/true else action $"Stopping $prog: " /bin/false echo "$prog is not running, but PID file exists" exit 1 fi else action $"Stopping $prog: " /bin/false echo "$prog is not running ..." exit 1 fi } restart(){ stop start } force_stop(){ killall php-cgi 2>/dev/null rm -rf $pid_file sleep 2 } force_reload(){ force_stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; force_reload) force_reload ;; force_stop) force_stop ;; *) echo $"Usage $prog: {start|stop|restart|force_reload|force_stop}" exit 1 ;; esac exit 0