emqttd_ctl 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/sh
  2. # -*- tab-width:4;indent-tabs-mode:nil -*-
  3. # ex: ts=4 sw=4 et
  4. # /bin/sh on Solaris is not a POSIX compatible shell, but /usr/bin/ksh is.
  5. if [ `uname -s` = 'SunOS' -a "${POSIX_SHELL}" != "true" ]; then
  6. POSIX_SHELL="true"
  7. export POSIX_SHELL
  8. # To support 'whoami' add /usr/ucb to path
  9. PATH=/usr/ucb:$PATH
  10. export PATH
  11. exec /usr/bin/ksh $0 "$@"
  12. fi
  13. unset POSIX_SHELL # clear it so if we invoke other scripts, they run as ksh as well
  14. RUNNER_SCRIPT_DIR={{runner_script_dir}}
  15. RUNNER_SCRIPT=${0##*/}
  16. RUNNER_BASE_DIR={{runner_base_dir}}
  17. RUNNER_ETC_DIR={{runner_etc_dir}}
  18. RUNNER_LIB_DIR={{platform_lib_dir}}
  19. RUNNER_LOG_DIR={{runner_log_dir}}
  20. RUNNER_USER={{runner_user}}
  21. WHOAMI=$(whoami)
  22. # Make sure this script is running as the appropriate user
  23. if ([ "$RUNNER_USER" ] && [ "x$WHOAMI" != "x$RUNNER_USER" ]); then
  24. type sudo > /dev/null 2>&1
  25. if [ $? -ne 0 ]; then
  26. echo "sudo doesn't appear to be installed and your EUID isn't $RUNNER_USER" 1>&2
  27. exit 1
  28. fi
  29. echo "Attempting to restart script through sudo -H -u $RUNNER_USER" >&2
  30. exec sudo -H -u $RUNNER_USER -i $RUNNER_SCRIPT_DIR/$RUNNER_SCRIPT $@
  31. fi
  32. # Make sure CWD is set to runner base dir
  33. cd $RUNNER_BASE_DIR
  34. # Extract the target node name from node.args
  35. NAME_ARG=`egrep "^ *-s?name" $RUNNER_ETC_DIR/vm.args`
  36. if [ -z "$NAME_ARG" ]; then
  37. echo "vm.args needs to have either -name or -sname parameter."
  38. exit 1
  39. fi
  40. # Learn how to specify node name for connection from remote nodes
  41. echo "$NAME_ARG" | grep '^-sname' > /dev/null 2>&1
  42. if [ "X$?" = "X0" ]; then
  43. NAME_PARAM="-sname"
  44. NAME_HOST=""
  45. else
  46. NAME_PARAM="-name"
  47. echo "$NAME_ARG" | grep '@.*' > /dev/null 2>&1
  48. if [ "X$?" = "X0" ]; then
  49. NAME_HOST=`echo "${NAME_ARG}" | sed -e 's/.*\(@.*\)$/\1/'`
  50. else
  51. NAME_HOST=""
  52. fi
  53. fi
  54. # Extract the target cookie
  55. COOKIE_ARG=`grep '\-setcookie' $RUNNER_ETC_DIR/vm.args`
  56. if [ -z "$COOKIE_ARG" ]; then
  57. echo "vm.args needs to have a -setcookie parameter."
  58. exit 1
  59. fi
  60. # Identify the script name
  61. SCRIPT=`basename $0`
  62. # Parse out release and erts info
  63. START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
  64. ERTS_VSN=${START_ERL% *}
  65. APP_VSN=${START_ERL#* }
  66. # Add ERTS bin dir to our path
  67. ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
  68. # Setup command to control the node
  69. NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
  70. RES=`$NODETOOL ping`
  71. if [ "$RES" != "pong" ]; then
  72. echo "Node is not running!"
  73. exit 1
  74. fi
  75. $NODETOOL rpc emqttd_ctl run $@