nginx啓動腳本

腳本思路:仿照httpd的啓動腳本,稍加修改即可。

注:省去了創建pid文件這一步。


腳本

#!/bin/sh 
# 
# nginx - this script starts and stops the nginx daemin 
# chkconfig: - 85 15 
# description: Nginx is an HTTP(S) server, HTTP(S) reverse
# proxy and IMAP/POP3 proxy server 
# processname: nginx 
# config: /usr/local/nginx/conf/nginx.conf 
# pidfile: /usr/local/nginx/logs/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 
ETVAL=0
nginx=/usr/local/nginx/sbin/nginx
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
#lockfile="/var/lock/subsys/nginx "
start() {
        echo -n $"Starting $prog: "
        daemon $nginx
        RETVAL=$?
        echo
        [ $RETVAL = 0 ]
        return $RETVAL
} 
stop() {
        echo -n $"Stopping $prog: "
        killall $nginx
        RETVAL=$?
        echo
        [ $RETVAL = 0 ]
}
reload() {
    echo -n $"Reloading $prog: "
    if ! $nginx -t >&/dev/null; then
        RETVAL=6
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $nginx due to configuration syntax error"
    else
        # Force LSB behaviour from killproc
        LSB=1 killall $nginx -HUP
        RETVAL=$?
        if [ $RETVAL -eq 7 ]; then
            failure $"httpd shutdown"
        fi
    fi
    echo
}
# See how we were called.
case "$1" in 
 start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart|try-restart)
        if status $prog >&/dev/null; then
                stop
                start
        fi
        ;;
  force-reload|reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $nginx -h
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
        RETVAL=2
esac
exit $RETVAL


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章