#!/bin/bash
#2019-03-23
#源码安装的nginx 启动脚本
#shell函数 case
. /etc/init.d/functions
NGINX_PATH=/usr/local/nginx/sbin
NGINX_PID=/usr/local/nginx/logs
function USG() {
echo "USAGE $0 {start | stop | restart}"
exit 1
}
function nginx_start() {
if [ -f "$NGINX_PID/nginx.pid" ];then
echo "Nginx already start."
return 1
fi
$NGINX_PATH/nginx
if [ $? -eq 0 ];then
action "start nginx " /bin/true
else
action " start nginx " /bin/false
fi
}
function nginx_stop() {
if [ ! -f "$NGINX_PID/nginx.pid" ];then
echo "Nginx already stop."
return 1
fi
$NGINX_PATH/nginx -s stop
if [ $? -eq 0 ];then
action "stop nginx " /bin/true
else
action " stop nginx " /bin/false
fi
/usr/bin/pkill nginx
}
function nginx_restart {
nginx_start
$NGINX_PATH/nginx -s reload
if [ $? -eq 0 ];then
action "restart nginx " /bin/true
else
action " restart nginx " /bin/false
fi
}
case $1 in
start)
nginx_start
;;
stop)
nginx_stop
;;
restart)
nginx_restart
;;
*)
USG
;;
esac