nginx启动脚本

 

[root@mail init.d]# nl /etc/init.d/nginx 
     1	#!/bin/bash
     2	# chkconfig: - 85 15
     3	# description: The Apache HTTP Server is an efficient and extensible  \
     4	#	       server implementing the current HTTP standards.
     5	#
     6	# Source function library.
     7	. /etc/rc.d/init.d/functions
     8	nginx=`which nginx`
     9	case $1 in
    10		start)
    11			num=`netstat -lanput | grep nginx | wc -l`
    12			if [ $num -gt 0 ]
    13			then
    14				echo "nginx is running"	
    15			else
    16				$nginx && echo -ne "nginx is started\t\t\t[ \033[31;48mok\033[0m ]\n"
    17			fi
    18		;;
    19		stop)
    20			num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    21			if [ $num2 -gt 0 ]
    22			then
    23				$nginx -s stop > /dev/null 2>&1	
    24				num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    25				if [ $num2 -gt 0 ]
    26		                then
    27					pkill -9 nginx
    28				fi
    29				num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    30				if [ $num2 -eq 0 ]
    31				then
    32					echo -ne "nginx is stoped\t\t\t[ \033[31;48mok\033[0m ]\n"
    33				else
    34					echo -ne "nginx is stoped\t\t\t[ \033[31;48mfaild\033[0m ]\n"
    35				fi
    36			fi
    37		;;
    38		restart)
    39			num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    40	                if [ $num2 -gt 0 ]
    41	                then
    42	                        $nginx -s stop > /dev/null 2>&1
    43	                        num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    44	                        if [ $num2 -gt 0 ]
    45	                        then
    46	                                pkill -9 nginx
    47	                        fi
    48	                        num2=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    49	                        if [ $num2 -eq 0 ]
    50	                        then
    51	                                echo -ne "nginx is stoped\t\t\t\t[ \033[31;48mok\033[0m ]\n"
    52	                        else
    53	                                echo -ne "nginx is stoped\t\t\t\t[ \033[31;48mfaild\033[0m ]\n"
    54	                        fi
    55	                fi
    56			num=`netstat -lanput | grep nginx | wc -l`
    57	                if [ $num -gt 0 ]
    58	                then
    59	                        echo "nginx is running" 
    60	                else
    61	                        $nginx && echo -ne "nginx is started\t\t\t[ \033[31;48mok\033[0m ]\n"
    62	                fi
    63		;;
    64		status)
    65			num=`ps -ef|grep "nginx:"|grep -v grep|wc -l`
    66	                if [ $num -eq 0 ]
    67	                then
    68				echo "nginx is stoped" 
    69			else
    70				echo "nginx is runing" 
    71			fi
    72		;;
    73		*)
    74			echo "Usage: nginx {start|stop|restart|status}"
    75		;;
    76	esac

  

posted @ 2016-05-08 09:13  similarface  阅读(222)  评论(0编辑  收藏  举报