Nginx啓動腳本(1)

第一步 先運行命令關閉nginx

#killall nginx

第二步 編輯服務腳本nginx

    /etc/init.d/nginx

# HTML files and CGI.

# processname: nginx 

# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx/nginx.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
if [ -f /etc/sysconfig/network ]; then
        . /etc/sysconfig/network
fi
 
# Path to the nginxd script, server binary, and short-form for messages.
nginx=/usr/sbin/nginx
prog=`basename $nginx`
pidfile=/var/run/nginx/nginx.pid
lockfile=/var/lock/subsys/nginx
NGINX_CONF_FILE=/etc/nginx/nginx.conf
RETVAL=0
 
start() {
        [ -x $nginx ] || exit 5
        [ -f $NGINX_CONF_FILE ] || exit 6
        echo -n $"Starting $prog: "
        daemon $nginx
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}
 
# When stopping nginx a delay of >10 second is required before SIGKILLing the
# nginx parent; this gives enough time for the nginx parent to SIGKILL any
# errant children.
stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d 10 $nginx
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
 
restart() {
        configtest || return $?
        stop
        start
}
 
reload() {
        configtest || return $?
        echo -n "Reloading $prog:"
        killproc -p ${pidfile} $nginx -HUP
        RETVAL=$?
        echo
}
 
configtest() {
        $nginx -t -c $NGINX_CONF_FILE
}
 
# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $nginx
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f ${pidfile} ] ; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  configtest)
        configtest
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|configtest}"
        exit 1
esac
 
exit $RETVAL
 
 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章