Nginx PHP-FPM 服务脚本

nginxphp-fpm 添加到系统服务:

vim /etc/init.d/nginx
# Copy the "nginx" into "/etc/init.d/nginx"
chmod 755 /etc/init.d/nginx
chkconfig --level 345 nginx on
vim /etc/init.d/php-fpm
# Copy the "php-fpm" into "/etc/init.d/nginx"
chmod 755 /etc/init.d/php-fpm
chkconfig --level 345 php-fpm on
# Or simply:
echo "/usr/sbin/nginx" >> /etc/rc.local
# Stop
pkill -9 nginx
# Reload
/usr/sbin/nginx -s reload
echo "/usr/sbin/php-fpm -y /etc/php-fpm.conf" >> /etc/rc.local
# Stop
pkill -9 php-fpm

Nginx:

#!/bin/bash
# v 0.0.1
# create by gesion<gesion@163.com>
# nginx - This shell script takes care of starting and stopping nginx.
#
# chkconfig: - 60 50
# description: nginx [engine x] is light http web/proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
nginx_path="/usr/sbin/nginx"
nginx_conf="/etc/nginx/nginx.conf"
nginx_lock="/var/lock/nginx.lock"
nginx_pid="/var/run/nginx.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
[ -x $nginx_path ] || exit 0
RETVAL=0
prog="nginx"
# Reload daemons.
reload() {
    if [ -e $nginx_pid -a ! -z $nginx_pid ]; then
        echo -n $"Reloading $prog: "
        $nginx_path -s reload && success || failure
        RETVAL=$?
        echo
    fi
    return $RETVAL
}
# Start daemons.
start() {
    if [ -e $nginx_pid -a ! -z $nginx_pid ]; then
        echo $"$prog already running..."
        exit 1
    fi
    if [ -e $nginx_conf ]; then
        echo -n $"Starting $prog: "
        $nginx_path -c $nginx_conf &
        RETVAL=$?
        [ $RETVAL -eq 0 ] && {
            touch $nginx_lock
            success $"$prog"
        }
        echo
    else
        RETVAL=1
    fi
    return $RETVAL
}
# Stop daemons.
stop() {
    echo -n $"Stopping $prog: "
    killproc -d 10 $nginx_path
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f $nginx_pid $nginx_lock
    return $RETVAL
}
# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    reload)
        # kill -HUP `cat $nginx_pid`
        reload
        ;;
    status)
         status $prog
         RETVAL=$?
         ;;
    *)
        echo $"Usage: $0 {start|stop|restart|reload|status}"
        exit 1
esac

exit $RETVAL

PHP-FPM:

#!/bin/bash
# v 0.0.1
# create by gesion<gesion@163.com>
# php-fpm - This shell script takes care of starting and stopping php-fpm.
#
# chkconfig: - 60 50
# description: php-fpm is a php-cgi service.
# processname: php-fpm
# config: /etc/php-fpm.ini
php_fpm_path="/usr/sbin/php-fpm"
php_fpm_conf="/etc/php-fpm.ini"
php_fpm_pid="/var/run/php-fpm.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
[ -x $php_fpm_path ] || exit 0
RETVAL=0
prog="php-fpm"
# Start daemons.
start() {
    if [ -e $php_fpm_pid -a ! -z $php_fpm_pid ]; then
        echo $"$prog already running..."
        exit 1
    fi
    if [ -e $php_fpm_conf ]; then
        echo -n $"Starting $prog: "
        $php_fpm_path -y $php_fpm_conf &
        RETVAL=$?
        [ $RETVAL -eq 0 ] && success $"$prog"
        echo
        [ $RETVAL -eq 0 ] && return $RETVAL
        pid created $php_fpm_pid
        if [ -n "$try" ]; then
            RETVAL=1
        else
            RETVAL=0
        fi
    else
        RETVAL=1
    fi
    return $RETVAL
}
# Stop daemons.
stop() {
    echo -n $"Stopping $prog: "
    killproc $php_fpm_path -TERM
    RETVAL=$?
    pid removed $php_fpm_pid
    if [ -n "$try" ]; then
        RETVAL=1
        failure
    else
        RETVAL=0
        success
    fi
    echo
    [ $RETVAL = 0 ] && rm -f $php_fpm_pid
    return $RETVAL
}
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
        try=$(expr $try + 1)
        sleep 1
    done
}
# See how we were called.
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
         status $prog
         RETVAL=$?
         ;;
    *)
        echo $"Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL

留下评论

电子邮件地址不会被公开。 必填项已用*标注