Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2113922
  • 博文数量: 227
  • 博客积分: 10521
  • 博客等级: 上将
  • 技术积分: 3452
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-20 14:59
个人简介

低调做人,高调做事!

文章分类

全部博文(227)

文章存档

2013年(4)

2012年(8)

2011年(16)

2010年(24)

2009年(92)

2008年(83)

分类: LINUX

2008-07-07 09:03:42



#!/bin/bash
#Use:Startup script for the nginx HTTP Server

#Definition Global environment variable
IFS=$' \t\n'
unset -f unalias
\unalias -a
unset -f command
SYSPATH="$(command -p getconf PATH >/dev/null 2>&1)"
if [[ -z "$SYSPATH" ]];then
SYSPATH="/bin:/usr/bin"
fi
export PATH="$SYSPATH:$PATH"
#Definition nginx directory & service name
NGINX_DIR="/usr/local/webserver/nginx"
PROG="nginx"
#Definition check listen conflict function
check_listen(){
echo -n "Checek $PROG Listen port status: "
NGINX_LISTEN=(`grep "^listen" ${NGINX_DIR}/conf/$PROG.conf | awk '{print $NF}' | cut -d";" -f1 | uniq`)
SYSTEM_LISTEN=(`netstat -tnl |awk '{print $4}' | grep [0-9] | awk -F":" '{print $NF}' | uniq `)
for FIR in ${NGINX_LISTEN[*]}; do
for SEC in ${SYSTEM_LISTEN[*]};do
if [ $FIR == $SEC ]; then
echo "Has the listen port conflict, please check $PROG config file ${NGINX_DIR}/conf/$PROG.conf"
break
fi
done
done
echo "listen prot status OK!"
}
#definition check uid function
check_uid(){
if [ `id -u ` != "0" ];then
echo "Error,The Script must be root to run"
exit 1
fi
}
#Definition start function
start() {
check_uid
${NGINX_DIR}/sbin/$PROG -t >/dev/null 2>&1
if [ $? == "0" ]; then
if [ `ps aux | grep $PROG | grep -c "master"` == "1" ]; then
echo -n $"Starting $PROG: "
echo "$PROG is already running"
exit 1
else
check_listen
${NGINX_DIR}/sbin/$PROG
echo -n $"Starting $PROG: "
echo "$PROG START OK"
fi
else
echo "$PROG syntax error,please check $PROG config file ${NGINX_DIR}/conf/$PROG.conf"
exit 2
fi
}
#Definition stop function
stop() {
check_uid
echo -n $"Stopping $PROG: "
if [ `ps aux | grep $PROG | grep -c "master"` == "1" ]; then
pkill $PROG
echo "$PROG stop OK"
else
echo "$PROG process does not exist.so $PROG stop failed"
fi
}
#Definition reload function
reload() {
check_uid
echo -n $"Reloading $PROG: "
${NGINX_DIR}/sbin/$PROG -t >/dev/null 2>&1
if [ $? == "0" ]; then
if [ `ps aux | grep $PROG | grep -c "master"` == "1" ]; then
kill -HUP `cat ${NGINX_DIR}/logs/$PROG.pid`
echo "$PROG reload OK"
exit 0
else
echo "$PROG process does not exist.so $PROG reload failed"
exit 1
fi
else
echo "$PROG syntax error,please check $PROG config file ${NGINX_DIR}/conf/$PROG.conf"
exit 2
fi
}
#Definition status function
status() {
if [ `ps aux | grep $PROG | grep -c "master"` == "1" ]; then
echo "$PROG status is running"
else
echo "$PROG status is stop"
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
reload)
reload
;;
configtest)
check_uid
${NGINX_DIR}/sbin/$PROG -t
;;
status)
status
;;
listentest)
check_uid
check_listen
;;
*)
echo $"Usage: $0{start|stop|restart|reload|configtest|status|listentest}"
exit 1
esac
#exit status code
exit $?
阅读(1906) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~