一个nginx的控制脚本,运行在CentOS Linux系统上,使用良好。代码如下:
#!/bin/bash
# master process
# TERM,INT shutdown fast
# QUIT shutdown graceful
# HUP reload config
# USR1 reopen log file
# USR2 update nginx bin file graceful
# WINCH shutdown worke prcess graceful
# work process
# TERM,INT shutdown fast
# QUIT shutdown graceful
# USR1 reopen log file
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
if [[ $NETWORKING == [Nn][Oo] ]]; then exit 0; fi
start() {
echo -n ‘Starting Nginx: ‘
#这里要指定你的nginx的路径: /opt/nginx/sbin/nginx
daemon /opt/nginx/sbin/nginx “$EXTRAOPTIONS”
local RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then touch /var/lock/subsys/nginx ; fi
return $RETVAL
}
stop() {
echo -n ‘Shutting down Nginx: ‘
killproc nginx
local RETVAL=$?
case nptl in
[Ll]inux[Tt]hreads*|lt*)
# Wait until all threads have terminated.
local -i count=20
while [[ count -gt 0 ]] && pidof nginx > /dev/null
do
usleep 200000
let –count
done
;;
esac
echo
if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/nginx; fi
return $RETVAL
}
restart() {
stop
start
}
relog() {
echo -n ‘Relog Nginx: ‘
killproc nginx -USR1
local RETVAL=$?
echo
return $RETVAL
}
reload() {
echo -n ‘Reload Nginx: ‘
killproc nginx -HUP
local RETVAL=$?
echo
return $RETVAL
}
check() {
/opt/nginx/sbin/nginx -t
}
#
# See how we were called.
#
case “$1″ in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
relog)
relog
;;
check)
check
;;
*)
echo $”Usage: nginxctl {start|stop|restart|reload|relog|check}”
exit 1
esac
exit
#!/bin/bash
# master process
# TERM,INT shutdown fast
# QUIT shutdown graceful
# HUP reload config
# USR1 reopen log file
# USR2 update nginx bin file graceful
# WINCH shutdown worke prcess graceful
# work process
# TERM,INT shutdown fast
# QUIT shutdown graceful
# USR1 reopen log file
PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
if [[ $NETWORKING == [Nn][Oo] ]]; then exit 0; fi
start() {
echo -n ‘Starting Nginx: ‘
#这里要指定你的nginx的路径: /opt/nginx/sbin/nginx
daemon /opt/nginx/sbin/nginx “$EXTRAOPTIONS”
local RETVAL=$?
echo
if [ $RETVAL -eq 0 ]; then touch /var/lock/subsys/nginx ; fi
return $RETVAL
}
stop() {
echo -n ‘Shutting down Nginx: ‘
killproc nginx
local RETVAL=$?
case nptl in
[Ll]inux[Tt]hreads*|lt*)
# Wait until all threads have terminated.
local -i count=20
while [[ count -gt 0 ]] && pidof nginx > /dev/null
do
usleep 200000
let –count
done
;;
esac
echo
if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/nginx; fi
return $RETVAL
}
restart() {
stop
start
}
relog() {
echo -n ‘Relog Nginx: ‘
killproc nginx -USR1
local RETVAL=$?
echo
return $RETVAL
}
reload() {
echo -n ‘Reload Nginx: ‘
killproc nginx -HUP
local RETVAL=$?
echo
return $RETVAL
}
check() {
/opt/nginx/sbin/nginx -t
}
#
# See how we were called.
#
case “$1″ in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
relog)
relog
;;
check)
check
;;
*)
echo $”Usage: nginxctl {start|stop|restart|reload|relog|check}”
exit 1
esac
exit