#!/bin/bash
# chkconfig: 2345 10 90
# description: nginx
. /etc/rc.d/init.d/functions
function show_usage(){
usage="Usage: `basename $0` [ start|stop|restart|reload ]"
echo $usage
exit
}
base_dir=/usr/local/nginx/
[[ $# != 1 ]] && show_usage
nginx=${base_dir}sbin/nginx
case $1 in
start)
[[ `netstat -ntlup|grep nginx|wc -l` > 0 ]] && failure && echo "Nginx is Running!" && exit
echo "Starting Nginx..."
$nginx
([ $? -eq 0 ] && success && echo "Nginx starts successfully!") || (failure && echo "Failed start nginx")
;;
stop)
[[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT running!" && exit
echo "Stopping Nginx..."
$nginx -s stop
([ $? -eq 0 ] && success && echo "Nginx stops successfully!") || (failure && echo "Failed stop nginx!")
;;
restart)
if [[ `netstat -ntlup|grep nginx|wc -l` == 0 ]]; then
echo "Starting Nginx..."
$nginx
[ $? -eq 0 ] && success && echo "Nginx starts successfully!"
else
echo "Stopping Nginx..."
$nginx -s stop
([ $? -eq 0 ] && success && echo "Nginx stops successfully!") || (failure && echo "Failed stop nginx!")
echo "Starting Nginx..."
$nginx
([ $? -eq 0 ] && success && echo "Nginx starts successfully!") || (failure && echo "Failed start nginx")
fi
;;
reload)
[[ `netstat -ntlup|grep nginx|wc -l` == 0 ]] && failure && echo "Nginx is NOT Running!" && exit
$nginx -s reload
[ $? -eq 0 ] && success && echo "Nginx reloads successfully!"
;;
*)
show_usage
;;
esac
发表评论