fast-try.sh 2.8 KB
Newer Older
1
#!/usr/bin/env bash
D
dongeforever 已提交
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
17 18 19 20 21 22

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

23
startNameserver() {
24 25 26 27
    export JAVA_OPT_EXT=" -Xms512m -Xmx512m  "
    nohup bin/mqnamesrv &
}

28
startBroker() {
29 30 31 32 33
    export JAVA_OPT_EXT=" -Xms1g -Xmx1g  "
    conf_name=$1
    nohup bin/mqbroker -c $conf_name &
}

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

41
stopBroker() {
42 43 44 45 46 47 48
    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
49
        i=`expr $i + 1`
50 51 52 53 54 55 56 57 58
        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
}

59
stopAll() {
60 61 62 63 64 65 66
    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
}

67
startAll() {
68 69 70 71 72 73
    startNameserver
    startBroker ./conf/dledger/broker-n0.conf
    startBroker ./conf/dledger/broker-n1.conf
    startBroker ./conf/dledger/broker-n2.conf
}

74
checkConf() {
75 76
    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"
77 78
        exit 1
    fi
79 80 81 82 83 84 85
}



## Main
if [ $# -lt 1 ]; then
    echo "Usage: sh $0 start|stop"
86
    exit 1
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
fi
action=$1
checkConf
case $action in
    "start")
        startAll
        exit
        ;;
    "stop")
        stopAll
        ;;
    *)
        echo "Usage: sh $0 start|stop"
        ;;
esac