首页 > 代码库 > nginx启动脚本

nginx启动脚本

#!/bin/sh 

# nginx - this script starts and stops the nginx daemin 

# chkconfig: - 85 15 

# description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 

# proxy and IMAP/POP3 proxy server 

# processname: nginx 

# config: /usr/local/nginx/conf/nginx.conf 

# pidfile: /usr/local/nginx/nginx.pid 


# Source function library. 

source /etc/init.d/functions


nginx="/usr/local/nginx/sbin/nginx"

name=`basename $nginx`

conf="/usr/local/nginx/conf/nginx.conf"

pid_file="/usr/local/nginx/nginx.pid"

pid=`pgrep nginx|head -1`



status() {

   if [ -f $pid_file ];then

      echo "$name 正在运行...."

   else

      echo "$name 已经停止...."

   fi

}


start() {

   if [ `netstat -ntlp|grep nginx|wc -l` -lt 1 ];then

      $nginx

      echo "启动 $name 成功...."

   else

      echo "$name 正在运行...."

   fi

}


stop() {

   if [ `netstat -ntlp|grep nginx|wc -l` -ge 1 ];then

     kill $pid

     echo "停止 $name 成功...."

   else

     echo "$name 已经停止...."

   fi

}


case $1 in

start)

   start

   ;;

stop)

   stop

   ;;

status)

   status

   ;;

restart)

   stop

   start

   ;;

reload)

   $nginx -s reload

   ;;

configtest)

   $nginx -t -c $conf

   ;;

*)

   echo "Uesr (start|stop|status|restart|reload|configtest)"

   ;;

esac


nginx启动脚本