CentOS 6.2企业级LNMP环境搭建(4)

/usr/local/php/sbin/php-fpm start 启动FastCGI
下面是伪sv启动FastCGI脚本,仅供参考。
vim /etc/init.d/phpfcgi 添加下面代码

#! /bin/sh
#
# phpcgi                Startup script for the Apache fastcgi Server
#
# chkconfig:345    85 15
# description:phpcgi    
# processname: phpcgi
# config: /usr/local/php/etc/php-fpm.conf
# pidfile: /usr/local/php/logs/php-fpm.pid
# Source function library.
. /etc/rc.d/init.d/functions

php_fpm_BIN=/usr/local/php/bin/php-cgi
php_fpm_CONF=/usr/local/php/etc/php-fpm.conf
php_fpm_PID=/usr/local/php/logs/php-fpm.pid


php_opts="--fpm-config $php_fpm_CONF"


wait_for_pid () {
                try=0

                while test $try -lt 35 ; do

                                case "$1" in
                                                'created')
                                                if [ -f "$2" ] ; then
                                                                try=''
                                                                break
                                                fi
                                                ;;

                                                'removed')
                                                if [ ! -f "$2" ] ; then
                                                                try=''
                                                                break
                                                fi
                                                ;;
                                esac

                                echo -n .
                                try=`expr $try + 1`
                                sleep 1

                done

}

case "$1" in
                start)
                                echo -n "Starting php_fpm "

                                $php_fpm_BIN --fpm $php_opts

                                if [ "$?" != 0 ] ; then
                                                echo " failed"
                                                echo -e "\033[31mStarting php_fpm .............[failed]\033[0m"
                                                exit 1
                                fi


                                wait_for_pid created $php_fpm_PID

                                if [ -n "$try" ] ; then
                                                echo " failed"
                                                echo -e "\033[31mStarting php_fpm .............[failed]\033[0m"
                                                exit 1
                                else
                                                echo " done"
                                fi
                                echo -e "\033[32mStarting php_fpm .............[ok]\033[0m"
                ;;

                stop)
                                echo -n "Shutting down php_fpm "

                                if [ ! -r $php_fpm_PID ] ; then
                                                echo -e "\033[31mwarning, no pid file found - php-fpm is not running ?\033[0m"
                                                exit 1
                                fi

                                kill -TERM `cat $php_fpm_PID`

                                wait_for_pid removed $php_fpm_PID

                                if [ -n "$try" ] ; then
                                                echo -e "\033[31mStoping php_fpm .............[failed]\033[0m"
                                                exit 1
                                else
                                                echo " done"
                                fi
                                echo -e "\033[32m Stoping php_fpm .............[ok]\033[0m"
                ;;

                quit)
                                echo -n "Gracefully shutting down php_fpm "

                                if [ ! -r $php_fpm_PID ] ; then
                                                echo -e "\033[31mwarning, no pid file found - php-fpm is not running ?\033[0m"
                                                exit 1
                                fi

                                kill -QUIT `cat $php_fpm_PID`

                                wait_for_pid removed $php_fpm_PID

                                if [ -n "$try" ] ; then
                                                echo -e "\033[31mquiting php_fpm .............[failed]\033[0m"
                                                exit 1
                                else
                                                echo " done"
                                fi
                                echo -e "\033[32mquiting    php_fpm .............[ok]\033[0m"
                ;;

                restart)
                                $0 stop
                                $0 start
                ;;

                reload)

                                echo -n "Reload service php-fpm "

                                if [ ! -r $php_fpm_PID ] ; then
                                                echo -e "\033[31mwarning, no pid file found - php-fpm is not running ?\033[0m"
                                                exit 1
                                fi

                                kill -USR2 `cat $php_fpm_PID`

                                echo -e "\033[32mreload    php_fpm .............[ok]\033[0m"
                ;;

                logrotate)

                                echo -n "Re-opening php-fpm log file "

                                if [ ! -r $php_fpm_PID ] ; then
                                                echo "warning, no pid file found - php-fpm is not running ?"
                                                exit 1
                                fi

                                kill -USR1 `cat $php_fpm_PID`

                                echo -e "\033[32mlogrotate    php_fpm .............[ok]\033[0m"
                ;;

                *)
                                echo -e "\033[32mUsage: $0 {start|stop|quit|restart|reload|logrotate}\033[0m"
                                exit 1
                ;;

esac

chmod +x /etc/init.d/phpfcgi
chkconfig --add phpfcgi


测试如下
[root@localhost ~]# service phpfcgi start
Starting php_fpm  done
Starting php_fpm .............[ok]
[root@localhost ~]# service phpfcgi stop
Shutting down php_fpm ...... done
 Stoping php_fpm .............[ok]

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/cda7205e809647dcb90cad78f57207a0.html