From 040a5f2e6e75847032e0346817f5d3fbda1a3aef Mon Sep 17 00:00:00 2001 From: dockerzhang Date: Wed, 17 Jun 2020 16:20:26 +0800 Subject: [PATCH] [TUBEMQ-240] add status command for broker/master script --- bin/broker.sh | 18 ++++++++++++++++-- bin/master.sh | 16 +++++++++++++++- bin/tubemq | 17 ++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/bin/broker.sh b/bin/broker.sh index a80d00669bd..51684e57642 100644 --- a/bin/broker.sh +++ b/bin/broker.sh @@ -44,7 +44,7 @@ AS_USER=`whoami` LOG_DIR="$BASE_DIR/logs" LOG_FILE="$LOG_DIR/broker.log" PID_DIR="$BASE_DIR/logs" -PID_FILE="$PID_DIR/.run.pid" +PID_FILE="$PID_DIR/.broker.run.pid" function running(){ if [ -f "$PID_FILE" ]; then @@ -83,6 +83,16 @@ function start_server() { chmod 755 $PID_FILE } +function status_server() { + if running; then + echo "Broker is running." + exit 0 + else + echo "Broker is not running." + exit 1 + fi +} + function stop_server() { if ! running; then echo "Broker is not running." @@ -107,7 +117,8 @@ function stop_server() { } function help() { - echo "Usage: broker.sh {start|stop|restart}" >&2 + echo "Usage: broker.sh {status|start|stop|restart}" >&2 + echo " status: the status of broker server" echo " start: start the broker server" echo " stop: stop the broker server" echo " restart: restart the broker server" @@ -116,6 +127,9 @@ function help() { command=$1 shift 1 case $command in + status) + status_server $@; + ;; start) start_server $@; ;; diff --git a/bin/master.sh b/bin/master.sh index 399fae13e9f..bd311a98c43 100644 --- a/bin/master.sh +++ b/bin/master.sh @@ -87,6 +87,16 @@ function start_server() { popd } +function status_server() { + if running; then + echo "Master is running." + exit 0 + else + echo "Master is not running." + exit 1 + fi +} + function stop_server() { if ! running; then echo "Master is not running." @@ -111,7 +121,8 @@ function stop_server() { } function help() { - echo "Usage: master.sh {start|stop|restart}" >&2 + echo "Usage: master.sh {status|start|stop|restart}" >&2 + echo " status: the status of master server" echo " start: start the master server" echo " stop: stop the master server" echo " restart: restart the master server" @@ -120,6 +131,9 @@ function help() { command=$1 shift 1 case $command in + status) + status_server $@; + ;; start) start_server $@; ;; diff --git a/bin/tubemq b/bin/tubemq index 6faf1de912a..3f375419d1f 100644 --- a/bin/tubemq +++ b/bin/tubemq @@ -85,6 +85,17 @@ function start_server() { popd } +# status of the specified service +function status_server() { + if running; then + echo "TubeMQ $SERVICE is running." + exit 0 + else + echo "TubeMQ $SERVICE is not running." + exit 1 + fi +} + # stop the specified service function stop_server() { if ! running; then @@ -111,7 +122,8 @@ function stop_server() { # display usage function help() { - echo "Usage: tubemq {master|broker} {start|stop|restart}" >&2 + echo "Usage: tubemq {master|broker} {status|start|stop|restart}" >&2 + echo " status: start the master/broker server" echo " start: start the master/broker server" echo " stop: stop the master/broker server" echo " restart: restart the master/broker server" @@ -146,6 +158,9 @@ LOG_FILE="$LOG_DIR/$SERVICE.log" PID_FILE="$PID_DIR/.$SERVICE.run.pid" case $COMMAND in + status) + status_server $@; + ;; start) start_server $@; ;;