码迷,mamicode.com
首页 > 其他好文 > 详细

nginx启动脚本

时间:2017-10-27 17:57:19      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:conf   sage   error   mkdir   nginx   log   stat   not run   name   

#!/bin/bash

CURRDIR=`dirname "$0"`
BASEDIR=`cd "$CURRDIR"; pwd`

NAME="nginx"
CMD=/usr/local/nginx/sbin/nginx

if [ "$1" = "-d" ]; then
    shift
    EXECUTEDIR=$1/
    shift
else
    EXECUTEDIR=$BASEDIR/
fi

if [ ! -d "$EXECUTEDIR" ]; then
    echo "ERROR: $EXECUTEDIR is not a dir"
    exit
fi

if [ ! -d "$EXECUTEDIR"/conf ]; then
    echo "ERROR: could not find $EXECUTEDIR/conf/"
    exit
fi

if [ ! -d "$EXECUTEDIR"/logs ]; then
    mkdir "$EXECUTEDIR"/logs
fi

cd "$EXECUTEDIR"
PID_FILE="$EXECUTEDIR"/logs/nginx.pd

check_pid() {
    RETVAL=1
    if [ -f $PID_FILE ]; then
        PID=`cat $PID_FILE`
        ls /proc/$PID &> /dev/null
        if [ $? -eq 0 ]; then
            RETVAL=0
        fi
    fi
}

check_running() {
    PID=0
    RETVAL=0
    check_pid
    if [ $RETVAL -eq 0 ]; then
        echo "$CMD is running as $PID, we‘ll do nothing"
        exit
    fi
}

start() {
    check_running
    #echo "$CMD -c $EXECUTEDIR/conf/nginx.conf -p $EXECUTEDIR"
    "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR"
}

stop() {
    "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR" -s stop
}

status() {
    check_pid
    if [ $RETVAL -eq 0 ]; then
        echo "nginx is running as $PID ..."
    else
        echo "nginx is not running"
    fi
}

reload() {
    "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR" -t
    if [ $? -ne 0 ]; then
        echo "test nginx conf fail. please check it first, we won‘t reload it"
        exit 1
    fi
    "$CMD" -c "$EXECUTEDIR/conf/nginx.conf" -p "$EXECUTEDIR" -s reload
}

RETVAL=0
case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    status)
        status
        ;;
    reload)
        reload
        ;;
    *)
    echo "Usage: $0 {start|stop|restart|status|reload}"
    RETVAL=1
esac
exit $RETVAL

 

nginx启动脚本

标签:conf   sage   error   mkdir   nginx   log   stat   not run   name   

原文地址:http://www.cnblogs.com/JahanGu/p/7744146.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!