nginx的启动脚本

nginx_path="/usr/local/nginx"
nginx_pid="/usr/local/nginx/var/nginx.pid"
fcgi_pid="/usr/local/nginx/var/fcgi.pid"
spawn_fcgi="/usr/local/php/bin/spawn-fcgi"
php_cgi="/usr/local/php/bin/php-cgi"
fcgi_user="www"
# Source function library.
. /etc/rc.d/init.d/functions

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

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

[ -x $nginx_path/sbin/nginx ] || exit 0

RETVAL=0
prog="nginx"

start() {
if [ -e $nginx_pid -a ! -z $nginx_pid ];then
    echo "nginx already running...."
    exit 1
fi


if [ -e $nginx_path/conf/nginx.conf ];then
    echo -n $"Starting $prog: "
    $nginx_path/sbin/nginx -c $nginx_path/conf/nginx.conf
    $spawn_fcgi -a 127.0.0.1 -p 10080 -C 32 -u $fcgi_user -f $php_cgi -P $fcgi_pid 2>/dev/null
    [ $RETVAL -eq 0 ] && {
        touch /var/lock/subsys/$prog
    }
else
  RETVAL=1
  fi
return $RETVAL
}

# Stop daemons.
stop() {
        echo -n $"Stopping $prog: "
        [ -f $fcgi_pid ] && {
            FCGIPID=`cat "$fcgi_pid"` 2>/dev/null
            /bin/kill "$FCGIPID" 2>/dev/null
            rm -fr $fcgi_pid
        }
        [ -f $nginx_pid ] && {
            NGINXPID=`cat "$nginx_pid"` 2>/dev/null
            /bin/kill "$NGINXPID" 2>/dev/null
            rm -fr $nginx_pid
        }
        sleep 1
        RETVAL=$?
        [ $RETVAL = 0 ] && rm -f $nginx_pid /var/lock/subsys/$prog
        return $RETVAL
}
reset() {
        echo -n $"Resetting $prog: "
        [ -f $nginx_pid ] && {
            NGINXPID=`cat "$nginx_pid"` 2>/dev/null
             /bin/kill -HUP "$NGINXPID" 2>/dev/null
        }

        RETVAL=$?
        return $RETVAL

}

case "$1" in
start)
        start
        RETVAL=$?
        if [ $RETVAL = 0 ];then
            echo [  OK  ]
        else
            echo [  Failed  ]
        fi
        ;;

stop)
        stop
        RETVAL=$?
        if [ $RETVAL = 0 ];then
            echo [  OK  ]
        else
            echo [  Failed  ]
        fi
        ;;

restart)
        stop
        RETVAL=$?
        if [ $RETVAL = 0 ];then
            echo [  OK  ]
        else
            echo [  Failed  ]
        fi
        start
        RETVAL=$?
        if [ $RETVAL = 0 ];then
            echo [  OK  ]
        else
            echo [  Failed  ]
        fi
        ;;
reload)
        reset
        RETVAL=$?
        if [ $RETVAL = 0 ];then
            echo [  OK  ]
        else
            echo [  Failed  ]
        fi
        ;;

status)
        status $prog
        RETVAL=$?
        ;;

*)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit $RETVAL

 

你可能感兴趣的:(nginx,PHP,function,user,cgi,networking)