# cat nginx
#!/bin/bash
#
# nginx - this script starts and stops the nginx deamon
#
#chkconfig: - 85 15
# 这一行表示的是nginx服务的启动级别, - 就是开机不启动,如果要指定级别,使用2345,指定不同的层次 85 和15 表示启动和关闭系统的优先级
#description: nginx is an http(s) server ,http(s) reverse proxy and IMAP/POP3 Proxy server
#大部分变量都在/etc/rc.d/init.d/functions和/etc/sysconfig/nginx 目录下
#processname: nginx
#config: /etc/nginx/nginx.conf
#config: /etc/sysconfig/nginx
#pidfile: /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
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
nginx_conf="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $nginx_conf ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $nginx_conf
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
retval=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $nginx_conf
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2&>1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart | configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force_reload)
$1
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|configtest}"
exit 2
esac
nginx 启动脚本
最新推荐文章于 2020-10-26 18:27:17 发布