Suse Linux Nginx自启动脚本

最近公司上一项目,系统使用的Suse Linux,原先红帽系列的Nginx SysV自启动脚本已经不适合了,基于此状况又特写了Suse Linux的Nginx自启动脚本
#! /bin/sh
#
# Nginx    -    Startup script for nginx
#
# chkconfig: - 85 15
# processname: nginx
# config: /etc/nginx/nginx.conf
# pidfile: /var/run/nginx/nginx.pid
# description: Nginx is an HTTP and reverse proxy server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 4 6
# Short-Description: start and stop nginx
# Author:沉醉寒风
# Email:liaoronghui@vip.qq.com
# Version:version 1.0
### END INIT INFO

# Source function library.
. /etc/rc.status

rc_reset
prog=nginx

NGINX_BIN="/usr/local/nginx/sbin/nginx"
CONFIG_FILE="/etc/nginx/nginx.conf"
PID_FILE="/var/run/nginx/nginx.pid"


if [ ! -x $NGINX_BIN ] ; then
    echo -n "$NGINX_BIN not installed! "
    # Tell the user this has skipped
    rc_status -s
    exit 5
fi

start() {
    if [ -e $PID_FILE ];then
        echo "$prog (pid  $(cat $PID_FILE)) already running..."
    else
        echo -n $"Starting $prog: "
        $NGINX_BIN -c $CONFIG_FILE
        rc_status -v
    fi
}

stop() {
    checkproc -p $PID_FILE $NGINX_BIN
    RETVAL=$?
    case $RETVAL in
        0)
            echo -n $"Shopping $prog: "
            killproc -p $PID_FILE -TERM $NGINX_BIN
            rc_status -v
            [ $? = 0 ] && rm -f $PID_FILE
            ;;
        *)
            echo  "Warning: $prog not running!"
            ;;
    esac    
}

configtest() {
    $NGINX_BIN -t -c $CONFIG_FILE
}

reload() {
    if [ -e $PID_FILE ];then
        echo -n $"Reloading $prog: "
        killproc -p $PID_FILE $NGINX_BIN -HUP
        rc_status -v
    else
        echo "Warning: $prog not running! "
        exit 1
    fi
}

status() {
    if [ -e $PID_FILE ];then
        echo "$prog (pid  $(cat $PID_FILE)) already running..."
    else
        echo "Warning: $prog not running! "
    fi
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    reload)
        reload
        ;;
    status)
        status
        ;;
    configtest)
        configtest
        ;;
        *)
        echo "Usage: $0 {start|stop|restart|reload|status|configtest}"
        exit 1
        ;;
esac
rc_exit