PageRenderTime 10ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/rel/files/ucengine-admin

http://github.com/AF83/ucengine
#! | 110 lines | 92 code | 18 blank | 0 comment | 0 complexity | b946906d24dfaeb680c473d49f839b7b MD5 | raw file
  1. #!/bin/bash
  2. # -*- tab-width:4;indent-tabs-mode:nil -*-
  3. # ex: ts=4 sw=4 et
  4. RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd)
  5. RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
  6. RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
  7. RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log
  8. PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
  9. RUNNER_USER=
  10. # Make sure this script is running as the appropriate user
  11. if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
  12. exec sudo -u $RUNNER_USER -i $0 $@
  13. fi
  14. # Make sure CWD is set to runner base dir
  15. cd $RUNNER_BASE_DIR
  16. # Make sure log directory exists
  17. mkdir -p $RUNNER_LOG_DIR
  18. # Extract the target node name from node.args
  19. NAME_ARG=`grep -e '-[s]*name' $RUNNER_ETC_DIR/vm.args`
  20. if [ -z "$NAME_ARG" ]; then
  21. echo "vm.args needs to have either -name or -sname parameter."
  22. exit 1
  23. fi
  24. NODE_ARG=`echo "${NAME_ARG}" | sed -e 's/-name \(.*\)$/--node \1/'`
  25. # Learn how to specify node name for connection from remote nodes
  26. echo "$NAME_ARG" | grep '^-sname' > /dev/null 2>&1
  27. if [ "X$?" = "X0" ]; then
  28. NAME_PARAM="-sname"
  29. NAME_HOST=""
  30. else
  31. NAME_PARAM="-name"
  32. echo "$NAME_ARG" | grep '@.*' > /dev/null 2>&1
  33. if [ "X$?" = "X0" ]; then
  34. NAME_HOST=`echo "${NAME_ARG}" | sed -e 's/.*\(@.*\)$/\1/'`
  35. else
  36. NAME_HOST=""
  37. fi
  38. fi
  39. # Extract the target cookie
  40. COOKIE_ARG=`grep -e '-setcookie' $RUNNER_ETC_DIR/vm.args`
  41. if [ -z "$COOKIE_ARG" ]; then
  42. echo "vm.args needs to have a -setcookie parameter."
  43. exit 1
  44. fi
  45. # Identify the script name
  46. SCRIPT=`basename $0`
  47. # Parse out release and erts info
  48. START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
  49. ERTS_VSN=${START_ERL% *}
  50. APP_VSN=${START_ERL#* }
  51. # Add ERTS bin dir to our path
  52. ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
  53. # Setup command to control the node
  54. NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
  55. internal_cmd()
  56. {
  57. $ERTS_PATH/erl -noshell $NAME_PARAM uce_ctl$NAME_HOST $COOKIE_ARG \
  58. -s uce_ctl \
  59. -dummy \
  60. "$@" \
  61. $NODE_ARG
  62. }
  63. tests()
  64. {
  65. $ERTS_PATH/erl -noshell $NAME_ARG \
  66. -config $RUNNER_ETC_DIR/app.config \
  67. -run ucengine_app \
  68. -eval "tests:start()."
  69. }
  70. fetch_metrics()
  71. {
  72. if [ -z $2 ];
  73. then
  74. echo "Please provide a destination folder"
  75. echo "$0 fetch_metrics /tmp/"
  76. exit 1
  77. fi
  78. NODE_UCENGINE=`echo "${NAME_ARG}" | sed -e 's/-name \(.*\)$/\1/'`
  79. EVAL="io:format(\"~p~n\", [rpc:call('$NODE_UCENGINE', metrics_counter, to_file, [\"$2/counter.csv\"])]), \
  80. io:format(\"~p~n\", [rpc:call('$NODE_UCENGINE', metrics_gauge, to_file, [\"$2/gauge.csv\"])]), \
  81. halt()."
  82. $ERTS_PATH/erl -noshell $NAME_PARAM metrics_dump$NAME_HOST $COOKIE_ARG \
  83. -dummy \
  84. -eval "$EVAL"
  85. }
  86. # Check the first argument for instructions
  87. case "$1" in
  88. --help) internal_cmd $@;;
  89. tests) tests $@;;
  90. fetch_metrics) fetch_metrics $@;;
  91. *) internal_cmd $@;;
  92. esac