emqttd_ctl 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. #!/bin/sh
  2. # /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/ksh is.
  3. if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
  4. POSIX_SHELL="true"
  5. export POSIX_SHELL
  6. # To support 'whoami' add /usr/ucb to path
  7. PATH=/usr/ucb:$PATH
  8. export PATH
  9. exec /usr/bin/ksh $0 "$@"
  10. fi
  11. unset POSIX_SHELL # clear it so if we invoke other scripts, they run as ksh as well
  12. RUNNER_SCRIPT_DIR={{runner_script_dir}}
  13. RUNNER_SCRIPT=${0##*/}
  14. RUNNER_BASE_DIR={{runner_base_dir}}
  15. RUNNER_ETC_DIR={{runner_etc_dir}}
  16. RUNNER_LIB_DIR={{platform_lib_dir}}
  17. RUNNER_LOG_DIR={{runner_log_dir}}
  18. RUNNER_USER={{runner_user}}
  19. WHOAMI=$(whoami)
  20. # Make sure this script is running as the appropriate user
  21. if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then
  22. type sudo > /dev/null 2>&1
  23. if [ $? -ne 0 ]; then
  24. echo "sudo doesn't appear to be installed and your EUID isn't $RUNNER_USER" 1>&2
  25. exit 1
  26. fi
  27. echo "Attempting to restart script through sudo -H -u $RUNNER_USER" >&2
  28. exec sudo -H -u $RUNNER_USER -i $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT $@
  29. fi
  30. # Make sure CWD is set to runner base dir
  31. cd $RUNNER_BASE_DIR
  32. # Extract the target node name from node.args
  33. NAME_ARG=`egrep "^ *-s?name" $RUNNER_ETC_DIR/vm.args`
  34. if [ -z "$NAME_ARG" ]; then
  35. echo "vm.args needs to have either -name or -sname parameter."
  36. exit 1
  37. fi
  38. # Learn how to specify node name for connection from remote nodes
  39. echo "$NAME_ARG" | grep '^-sname' > /dev/null 2>&1
  40. if [ "X$?" = "X0" ]; then
  41. NAME_PARAM="-sname"
  42. NAME_HOST=""
  43. else
  44. NAME_PARAM="-name"
  45. echo "$NAME_ARG" | grep '@.*' > /dev/null 2>&1
  46. if [ "X$?" = "X0" ]; then
  47. NAME_HOST=`echo "${NAME_ARG}" | sed -e 's/.*\(@.*\)$/\1/'`
  48. else
  49. NAME_HOST=""
  50. fi
  51. fi
  52. # Extract the target cookie
  53. COOKIE_ARG=`grep '\-setcookie' $RUNNER_ETC_DIR/vm.args`
  54. if [ -z "$COOKIE_ARG" ]; then
  55. echo "vm.args needs to have a -setcookie parameter."
  56. exit 1
  57. fi
  58. # Identify the script name
  59. SCRIPT=`basename $0`
  60. # Parse out release and erts info
  61. START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
  62. ERTS_VSN=${START_ERL% *}
  63. APP_VSN=${START_ERL#* }
  64. # Add ERTS bin dir to our path
  65. ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
  66. # Setup command to control the node
  67. NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
  68. # Check the first argument for instructions
  69. case "$1" in
  70. status)
  71. if [ $# -ne 1 ]; then
  72. echo "Usage: $SCRIPT status"
  73. exit 1
  74. fi
  75. RES=`$NODETOOL ping`
  76. if [ "$RES" != "pong" ]; then
  77. echo "Node is not running!"
  78. exit 1
  79. fi
  80. shift
  81. $NODETOOL rpc emqttd_ctl status $@
  82. ;;
  83. cluster)
  84. if [ $# -gt 2 ]; then
  85. echo "Usage: $SCRIPT cluster [<Node>]"
  86. exit 1
  87. fi
  88. # Make sure the local node IS running
  89. RES=`$NODETOOL ping`
  90. if [ "$RES" != "pong" ]; then
  91. echo "emqttd is not running!"
  92. exit 1
  93. fi
  94. shift
  95. $NODETOOL rpc emqttd_ctl cluster $@
  96. ;;
  97. useradd)
  98. if [ $# -ne 3 ]; then
  99. echo "Usage: $SCRIPT useradd <Username> <Password>"
  100. exit 1
  101. fi
  102. # Make sure the local node IS running
  103. RES=`$NODETOOL ping`
  104. if [ "$RES" != "pong" ]; then
  105. echo "emqttd is not running!"
  106. exit 1
  107. fi
  108. shift
  109. $NODETOOL rpc emqttd_ctl useradd $@
  110. ;;
  111. userdel)
  112. if [ $# -ne 2 ]; then
  113. echo "Usage: $SCRIPT userdel <Username>"
  114. exit 1
  115. fi
  116. # Make sure the local node IS running
  117. RES=`$NODETOOL ping`
  118. if [ "$RES" != "pong" ]; then
  119. echo "emqttd is not running!"
  120. exit 1
  121. fi
  122. shift
  123. $NODETOOL rpc emqttd_ctl userdel $@
  124. ;;
  125. vm)
  126. if [ $# -gt 2 ]; then
  127. echo "Usage: $SCRIPT vm [ load | memory | process | io ]"
  128. exit 1
  129. fi
  130. # Make sure the local node IS running
  131. RES=`$NODETOOL ping`
  132. if [ "$RES" != "pong" ]; then
  133. echo "emqttd is not running!"
  134. exit 1
  135. fi
  136. shift
  137. $NODETOOL rpc emqttd_ctl vm $@
  138. ;;
  139. broker)
  140. if [ $# -ne 1 ]; then
  141. echo "Usage: $SCRIPT broker"
  142. exit 1
  143. fi
  144. # Make sure the local node IS running
  145. RES=`$NODETOOL ping`
  146. if [ "$RES" != "pong" ]; then
  147. echo "emqttd is not running!"
  148. exit 1
  149. fi
  150. shift
  151. $NODETOOL rpc emqttd_ctl broker $@
  152. ;;
  153. stats)
  154. if [ $# -ne 1 ]; then
  155. echo "Usage: $SCRIPT stats"
  156. exit 1
  157. fi
  158. # Make sure the local node IS running
  159. RES=`$NODETOOL ping`
  160. if [ "$RES" != "pong" ]; then
  161. echo "emqttd is not running!"
  162. exit 1
  163. fi
  164. shift
  165. $NODETOOL rpc emqttd_ctl stats $@
  166. ;;
  167. metrics)
  168. if [ $# -ne 1 ]; then
  169. echo "Usage: $SCRIPT metrics"
  170. exit 1
  171. fi
  172. # Make sure the local node IS running
  173. RES=`$NODETOOL ping`
  174. if [ "$RES" != "pong" ]; then
  175. echo "emqttd is not running!"
  176. exit 1
  177. fi
  178. shift
  179. $NODETOOL rpc emqttd_ctl metrics $@
  180. ;;
  181. bridges)
  182. # Make sure the local node IS running
  183. RES=`$NODETOOL ping`
  184. if [ "$RES" != "pong" ]; then
  185. echo "emqttd is not running!"
  186. exit 1
  187. fi
  188. if [[ $# -eq 2 ]] && [[ $2 = "list" ]]; then
  189. $NODETOOL rpc emqttd_ctl bridges list
  190. elif [ $# -eq 4 ]; then
  191. shift
  192. $NODETOOL rpc emqttd_ctl bridges $@
  193. else
  194. echo "Usage: "
  195. echo "$SCRIPT bridges list"
  196. echo "$SCRIPT bridges start <Node> <Topic>"
  197. echo "$SCRIPT bridges stop <Node> <Topic>"
  198. exit 1
  199. fi
  200. ;;
  201. plugins)
  202. # Make sure the local node IS running
  203. RES=`$NODETOOL ping`
  204. if [ "$RES" != "pong" ]; then
  205. echo "emqttd is not running!"
  206. exit 1
  207. fi
  208. if [ $# -eq 2 -a $2 = "list" ]; then
  209. $NODETOOL rpc emqttd_ctl plugins list
  210. elif [ $# -eq 3 ]; then
  211. shift
  212. $NODETOOL rpc emqttd_ctl plugins $@
  213. else
  214. echo "Usage: "
  215. echo "$SCRIPT plugins list"
  216. echo "$SCRIPT plugins load <Plugin>"
  217. echo "$SCRIPT plugins unload <Plugin>"
  218. exit 1
  219. fi
  220. ;;
  221. listeners)
  222. if [ $# -gt 1 ]; then
  223. echo "Usage: $SCRIPT listeners"
  224. exit 1
  225. fi
  226. # Make sure the local node IS running
  227. RES=`$NODETOOL ping`
  228. if [ "$RES" != "pong" ]; then
  229. echo "emqttd is not running!"
  230. exit 1
  231. fi
  232. shift
  233. $NODETOOL rpc emqttd_ctl listeners $@
  234. ;;
  235. trace)
  236. # Make sure the local node IS running
  237. RES=`$NODETOOL ping`
  238. if [ "$RES" != "pong" ]; then
  239. echo "emqttd is not running!"
  240. exit 1
  241. fi
  242. if [ $# -eq 2 -a $2 = "list" ]; then
  243. $NODETOOL rpc emqttd_ctl trace list
  244. elif [ $# -eq 4 ]; then
  245. shift
  246. $NODETOOL rpc emqttd_ctl trace $@
  247. else
  248. echo "Usage: "
  249. echo "$SCRIPT trace list"
  250. echo "$SCRIPT trace client <ClientId> <LogFile>"
  251. echo "$SCRIPT trace client <ClientId> off"
  252. echo "$SCRIPT trace topic <Topic> <LogFile>"
  253. echo "$SCRIPT trace topic <Topic> off"
  254. exit 1
  255. fi
  256. ;;
  257. *)
  258. echo "Usage: $SCRIPT"
  259. echo " status #query broker status"
  260. echo " vm [ load | memory | process | io ] #query load, memory, process and io of erlang vm"
  261. echo " broker #query broker version, uptime and description"
  262. echo " stats #query broker statistics of clients, topics, subscribers"
  263. echo " metrics #query broker metrics"
  264. echo " cluster [<Node>] #query or cluster nodes"
  265. echo " ----------------------------------------------------------------"
  266. echo " plugins list #query loaded plugins"
  267. echo " plugins load <Plugin> #load plugin"
  268. echo " plugins unload <Plugin> #unload plugin"
  269. echo " ----------------------------------------------------------------"
  270. echo " bridges list #query bridges"
  271. echo " bridges start <Node> <Topic> #start bridge"
  272. echo " bridges stop <Node> <Topic> #stop bridge"
  273. echo " ----------------------------------------------------------------"
  274. echo " useradd <Username> <Password> #add user"
  275. echo " userdel <Username> #delete user"
  276. echo " ----------------------------------------------------------------"
  277. echo " listeners #query broker listeners"
  278. echo " ----------------------------------------------------------------"
  279. echo " trace list #query all traces"
  280. echo " trace client <ClientId> <LogFile> #trace client with ClientId"
  281. echo " trace client <ClientId> off #stop to trace client"
  282. echo " trace topic <Topic> <LogFile> #trace topic with Topic"
  283. echo " trace topic <Topic> off #stop to trace Topic"
  284. exit 1
  285. ;;
  286. esac