您的位置:首页 > 运维架构 > Nginx

nginx启动和停止脚本

2009-06-10 18:28 351 查看
#!/bin/bash
# Nginx service controll
# chkconfig: - 85 15
# description: A faster www server
. /etc/rc.d/init.d/functions
prog="Nginx"
prog_name="nginx"
pid_file="/usr/local/nginx/nginx.pid"
bin_file="/usr/local/nginx/sbin/$prog_name"
user="httpd"
group="httpd"
conf_file="/usr/local/nginx/conf/nginx.conf"
test_config(){
# Test configuration
$bin_file -t -c $conf_file
}
start(){
if [ -f "$pid_file" ]; then
action $"Startting $prog: " /bin/false
echo "$prog is running ..."
exit 1
else
$bin_file -c $conf_file>/dev/null
if [ -f "$pid_file" ]; then
action $"Startting $prog: " /bin/true
else
action $"Startting $prog: " /bin/false
echo "Some unexcepted errors occupied ..."
fi
fi
}
stop(){
if [ -f "$pid_file" ]; then
pid=`cat "$pid_file"`
if kill -0 $pid 2>/dev/null; then
kill $pid
rm -rf $pid_file
action $"Stopping $prog: " /bin/true
else
action $"Stopping $prog: " /bin/false
echo "$prog is not running, but PID file exists"
exit 1
fi
else
action $"Stoppng $prog: " /bin/false
echo "$prog is not running ..."
exit 1
fi
}
force_stop(){
killall $prog_name>/dev/null
rm -rf $pid_file
sleep 2
action $"Force stopping $prog: " /bin/true
}
restart(){
stop
start
}
force_reload(){
force_stop
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
force_reload)
force_reload
;;
force_stop)
force_stop
;;
test)
test_config
;;
*)
echo $"Usage $prog: {start|stop|restart|test|force_stop|force_reload}"
exit 1
;;
esac
exit 0
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: