From 26c371dff85caa05ef2e044bd88d02ed96cae5aa Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Wed, 30 Sep 2015 03:06:45 +0800 Subject: [PATCH] cli --- rel/files/emqttd_ctl | 304 +--------------------------------------- rel/files/emqttd_ctl.bk | 300 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 306 insertions(+), 298 deletions(-) create mode 100644 rel/files/emqttd_ctl.bk diff --git a/rel/files/emqttd_ctl b/rel/files/emqttd_ctl index ccba93740..8a65bd6d3 100755 --- a/rel/files/emqttd_ctl +++ b/rel/files/emqttd_ctl @@ -79,303 +79,11 @@ ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin # Setup command to control the node NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG" -# Check the first argument for instructions -case "$1" in - status) - if [ $# -ne 1 ]; then - echo "Usage: $SCRIPT status" - exit 1 - fi +RES=`$NODETOOL ping` +if [ "$RES" != "pong" ]; then + echo "Node is not running!" + exit 1 +fi - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "Node is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl status $@ - ;; - - cluster) - if [ $# -gt 2 ]; then - echo "Usage: $SCRIPT cluster []" - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl cluster $@ - ;; - - useradd) - if [ $# -ne 3 ]; then - echo "Usage: $SCRIPT useradd " - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl useradd $@ - ;; - - userdel) - if [ $# -ne 2 ]; then - echo "Usage: $SCRIPT userdel " - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl userdel $@ - ;; - - vm) - if [ $# -gt 2 ]; then - echo "Usage: $SCRIPT vm [ load | memory | process | io ]" - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl vm $@ - ;; - - broker) - if [ $# -ne 1 ]; then - echo "Usage: $SCRIPT broker" - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl broker $@ - ;; - - stats) - if [ $# -ne 1 ]; then - echo "Usage: $SCRIPT stats" - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl stats $@ - ;; - - metrics) - if [ $# -ne 1 ]; then - echo "Usage: $SCRIPT metrics" - exit 1 - fi - - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl metrics $@ - ;; - - bridges) - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - if [[ $# -eq 2 ]] && [[ $2 = "list" ]]; then - $NODETOOL rpc emqttd_ctl bridges list - elif [[ $# -eq 2 ]] && [[ $2 = "options" ]]; then - $NODETOOL rpc emqttd_ctl bridges options - elif [[ $# -eq 4 ]] && [[ $2 = "stop" ]]; then - shift - $NODETOOL rpc emqttd_ctl bridges $@ - elif [[ $# -ge 4 ]] && [[ $2 = "start" ]]; then - shift - $NODETOOL rpc emqttd_ctl bridges $@ - else - echo "Usage: " - echo "$SCRIPT bridges list" - echo "$SCRIPT bridges start " - echo "$SCRIPT bridges start " - echo "$SCRIPT bridges stop " - exit 1 - fi - ;; - clients) - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - if [ $# -eq 2 -a $2 = "list" ]; then - $NODETOOL rpc emqttd_ctl clients list - elif [ $# -eq 3 ]; then - shift - $NODETOOL rpc emqttd_ctl clients $@ - else - echo "Usage: " - echo "$SCRIPT clients list" - echo "$SCRIPT clients show " - echo "$SCRIPT clients kick " - exit 1 - fi - ;; - sessions) - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - if [ $# -eq 2 -a $2 = "list" ]; then - $NODETOOL rpc emqttd_ctl sessions list - elif [ $# -eq 3 ]; then - shift - $NODETOOL rpc emqttd_ctl sessions $@ - else - echo "Usage: " - echo "$SCRIPT sessions list" - echo "$SCRIPT sessions show " - exit 1 - fi - ;; - plugins) - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - if [ $# -eq 2 -a $2 = "list" ]; then - $NODETOOL rpc emqttd_ctl plugins list - elif [ $# -eq 3 ]; then - shift - $NODETOOL rpc emqttd_ctl plugins $@ - else - echo "Usage: " - echo "$SCRIPT plugins list" - echo "$SCRIPT plugins load " - echo "$SCRIPT plugins unload " - exit 1 - fi - ;; - listeners) - if [ $# -gt 1 ]; then - echo "Usage: $SCRIPT listeners" - exit 1 - fi - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - shift - - $NODETOOL rpc emqttd_ctl listeners $@ - ;; - trace) - # Make sure the local node IS running - RES=`$NODETOOL ping` - if [ "$RES" != "pong" ]; then - echo "emqttd is not running!" - exit 1 - fi - if [ $# -eq 2 -a $2 = "list" ]; then - $NODETOOL rpc emqttd_ctl trace list - elif [ $# -eq 4 ]; then - shift - $NODETOOL rpc emqttd_ctl trace $@ - else - echo "Usage: " - echo "$SCRIPT trace list" - echo "$SCRIPT trace client " - echo "$SCRIPT trace client off" - echo "$SCRIPT trace topic " - echo "$SCRIPT trace topic off" - exit 1 - fi - ;; - - *) - echo "Usage: $SCRIPT" - echo " status #query broker status" - echo " vm [ load | memory | process | io ] #query load, memory, process and io of erlang vm" - echo " broker #query broker version, uptime and description" - echo " stats #query broker statistics of clients, topics, subscribers" - echo " metrics #query broker metrics" - echo " cluster [] #query or cluster nodes" - echo " ----------------------------------------------------------------" - echo " clients list #list all clients" - echo " clients show #show a client" - echo " clients kick #kick a client" - echo " sessions list #list all sessions" - echo " sessions show #show a sessions" - echo " ----------------------------------------------------------------" - echo " plugins list #query loaded plugins" - echo " plugins load #load plugin" - echo " plugins unload #unload plugin" - echo " ----------------------------------------------------------------" - echo " bridges list #query bridges" - echo " bridges options #bridge options" - echo " bridges start #start bridge" - echo " bridges start #start bridge with options" - echo " bridges stop #stop bridge" - echo " ----------------------------------------------------------------" - echo " useradd #add user" - echo " userdel #delete user" - echo " ----------------------------------------------------------------" - echo " listeners #query broker listeners" - echo " ----------------------------------------------------------------" - echo " trace list #query all traces" - echo " trace client #trace client with ClientId" - echo " trace client off #stop to trace client" - echo " trace topic #trace topic with Topic" - echo " trace topic off #stop to trace Topic" - exit 1 - ;; - -esac +$NODETOOL rpc emqttd_ctl run $@ diff --git a/rel/files/emqttd_ctl.bk b/rel/files/emqttd_ctl.bk new file mode 100644 index 000000000..606562e88 --- /dev/null +++ b/rel/files/emqttd_ctl.bk @@ -0,0 +1,300 @@ +# Check the first argument for instructions +case "$1" in + status) + if [ $# -ne 1 ]; then + echo "Usage: $SCRIPT status" + exit 1 + fi + + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "Node is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl status $@ + ;; + + cluster) + if [ $# -gt 2 ]; then + echo "Usage: $SCRIPT cluster []" + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl cluster $@ + ;; + + useradd) + if [ $# -ne 3 ]; then + echo "Usage: $SCRIPT useradd " + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl useradd $@ + ;; + + userdel) + if [ $# -ne 2 ]; then + echo "Usage: $SCRIPT userdel " + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl userdel $@ + ;; + + vm) + if [ $# -gt 2 ]; then + echo "Usage: $SCRIPT vm [ load | memory | process | io ]" + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl vm $@ + ;; + + broker) + if [ $# -ne 1 ]; then + echo "Usage: $SCRIPT broker" + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl broker $@ + ;; + + stats) + if [ $# -ne 1 ]; then + echo "Usage: $SCRIPT stats" + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl stats $@ + ;; + + metrics) + if [ $# -ne 1 ]; then + echo "Usage: $SCRIPT metrics" + exit 1 + fi + + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl metrics $@ + ;; + + bridges) + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + if [[ $# -eq 2 ]] && [[ $2 = "list" ]]; then + $NODETOOL rpc emqttd_ctl bridges list + elif [[ $# -eq 2 ]] && [[ $2 = "options" ]]; then + $NODETOOL rpc emqttd_ctl bridges options + elif [[ $# -eq 4 ]] && [[ $2 = "stop" ]]; then + shift + $NODETOOL rpc emqttd_ctl bridges $@ + elif [[ $# -ge 4 ]] && [[ $2 = "start" ]]; then + shift + $NODETOOL rpc emqttd_ctl bridges $@ + else + echo "Usage: " + echo "$SCRIPT bridges list" + echo "$SCRIPT bridges start " + echo "$SCRIPT bridges start " + echo "$SCRIPT bridges stop " + exit 1 + fi + ;; + clients) + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + if [ $# -eq 2 -a $2 = "list" ]; then + $NODETOOL rpc emqttd_ctl clients list + elif [ $# -eq 3 ]; then + shift + $NODETOOL rpc emqttd_ctl clients $@ + else + echo "Usage: " + echo "$SCRIPT clients list" + echo "$SCRIPT clients show " + echo "$SCRIPT clients kick " + exit 1 + fi + ;; + sessions) + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + if [ $# -eq 2 -a $2 = "list" ]; then + $NODETOOL rpc emqttd_ctl sessions list + elif [ $# -eq 3 ]; then + shift + $NODETOOL rpc emqttd_ctl sessions $@ + else + echo "Usage: " + echo "$SCRIPT sessions list" + echo "$SCRIPT sessions show " + exit 1 + fi + ;; + plugins) + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + if [ $# -eq 2 -a $2 = "list" ]; then + $NODETOOL rpc emqttd_ctl plugins list + elif [ $# -eq 3 ]; then + shift + $NODETOOL rpc emqttd_ctl plugins $@ + else + echo "Usage: " + echo "$SCRIPT plugins list" + echo "$SCRIPT plugins load " + echo "$SCRIPT plugins unload " + exit 1 + fi + ;; + listeners) + if [ $# -gt 1 ]; then + echo "Usage: $SCRIPT listeners" + exit 1 + fi + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + shift + + $NODETOOL rpc emqttd_ctl listeners $@ + ;; + trace) + # Make sure the local node IS running + RES=`$NODETOOL ping` + if [ "$RES" != "pong" ]; then + echo "emqttd is not running!" + exit 1 + fi + if [ $# -eq 2 -a $2 = "list" ]; then + $NODETOOL rpc emqttd_ctl trace list + elif [ $# -eq 4 ]; then + shift + $NODETOOL rpc emqttd_ctl trace $@ + else + echo "Usage: " + echo "$SCRIPT trace list" + echo "$SCRIPT trace client " + echo "$SCRIPT trace client off" + echo "$SCRIPT trace topic " + echo "$SCRIPT trace topic off" + exit 1 + fi + ;; + + *) + echo "Usage: $SCRIPT" + echo " status #query broker status" + echo " vm [ load | memory | process | io ] #query load, memory, process and io of erlang vm" + echo " broker #query broker version, uptime and description" + echo " stats #query broker statistics of clients, topics, subscribers" + echo " metrics #query broker metrics" + echo " cluster [] #query or cluster nodes" + echo " ----------------------------------------------------------------" + echo " clients list #list all clients" + echo " clients show #show a client" + echo " clients kick #kick a client" + echo " sessions list #list all sessions" + echo " sessions show #show a sessions" + echo " ----------------------------------------------------------------" + echo " plugins list #query loaded plugins" + echo " plugins load #load plugin" + echo " plugins unload #unload plugin" + echo " ----------------------------------------------------------------" + echo " bridges list #query bridges" + echo " bridges options #bridge options" + echo " bridges start #start bridge" + echo " bridges start #start bridge with options" + echo " bridges stop #stop bridge" + echo " ----------------------------------------------------------------" + echo " useradd #add user" + echo " userdel #delete user" + echo " ----------------------------------------------------------------" + echo " listeners #query broker listeners" + echo " ----------------------------------------------------------------" + echo " trace list #query all traces" + echo " trace client #trace client with ClientId" + echo " trace client off #stop to trace client" + echo " trace topic #trace topic with Topic" + echo " trace topic off #stop to trace Topic" + exit 1 + ;; + +esac +