fast-try.sh 2.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
#! /bin/bash 

## Revise the base dir
CURRENT_DIR="$(cd "$(dirname "$0")"; pwd)"
RMQ_DIR=$CURRENT_DIR/../..
cd $RMQ_DIR

function startNameserver() {
    export JAVA_OPT_EXT=" -Xms512m -Xmx512m  "
    nohup bin/mqnamesrv &
}

function startBroker() {
    export JAVA_OPT_EXT=" -Xms1g -Xmx1g  "
    conf_name=$1
    nohup bin/mqbroker -c $conf_name &
}

function stopNameserver() {
    PIDS=$(ps -ef|grep java|grep NamesrvStartup|grep -v grep|awk '{print $2}')
    if [ ! -z "$PIDS" ]; then
        kill -s TERM $PIDS
    fi
}

function stopBroker() {
    conf_name=$1
    PIDS=$(ps -ef|grep java|grep BrokerStartup|grep $conf_name|grep -v grep|awk '{print $2}')
    i=1
    while [ ! -z "$PIDS" -a $i -lt 5 ]
    do
        echo "Waiting to kill ..."
        kill -s TERM $PIDS
        ((i=$i+1))
        sleep 2
        PIDS=$(ps -ef|grep java|grep BrokerStartup|grep $conf_name|grep -v grep|awk '{print $2}')
    done
    PIDS=$(ps -ef|grep java|grep BrokerStartup|grep $conf_name|grep -v grep|awk '{print $2}')
    if [ ! -z "$PIDS" ]; then
        kill -9 $PIDS
    fi
}

function stopAll() {
    ps -ef|grep java|grep BrokerStartup|grep -v grep|awk '{print $2}'|xargs kill
    stopNameserver
    stopBroker ./conf/dledger/broker-n0.conf
    stopBroker ./conf/dledger/broker-n1.conf
    stopBroker ./conf/dledger/broker-n2.conf
}

function startAll() {
    startNameserver
    startBroker ./conf/dledger/broker-n0.conf
    startBroker ./conf/dledger/broker-n1.conf
    startBroker ./conf/dledger/broker-n2.conf
}

function checkConf() {
    if [ ! -f ./conf/dledger/broker-n0.conf -o ! -f ./conf/dledger/broker-n1.conf -o ! -f ./conf/dledger/broker-n2.conf ]; then
        echo "Make sure the ./conf/dledger/broker-n0.conf, ./conf/dledger/broker-n1.conf, ./conf/dledger/broker-n2.conf exists"
        exit -1
    fi 
}



## Main
if [ $# -lt 1 ]; then
    echo "Usage: sh $0 start|stop"
    exit -1
fi
action=$1
checkConf
case $action in
    "start")
        startAll
        exit
        ;;
    "stop")
        stopAll
        ;;
    *)
        echo "Usage: sh $0 start|stop"
        ;;
esac