/rel/files/ucengine-admin
#! | 110 lines | 92 code | 18 blank | 0 comment | 0 complexity | b946906d24dfaeb680c473d49f839b7b MD5 | raw file
- #!/bin/bash
- # -*- tab-width:4;indent-tabs-mode:nil -*-
- # ex: ts=4 sw=4 et
- RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd)
- RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
- RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
- RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log
- PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
- RUNNER_USER=
- # Make sure this script is running as the appropriate user
- if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
- exec sudo -u $RUNNER_USER -i $0 $@
- fi
- # Make sure CWD is set to runner base dir
- cd $RUNNER_BASE_DIR
- # Make sure log directory exists
- mkdir -p $RUNNER_LOG_DIR
- # Extract the target node name from node.args
- NAME_ARG=`grep -e '-[s]*name' $RUNNER_ETC_DIR/vm.args`
- if [ -z "$NAME_ARG" ]; then
- echo "vm.args needs to have either -name or -sname parameter."
- exit 1
- fi
- NODE_ARG=`echo "${NAME_ARG}" | sed -e 's/-name \(.*\)$/--node \1/'`
- # Learn how to specify node name for connection from remote nodes
- echo "$NAME_ARG" | grep '^-sname' > /dev/null 2>&1
- if [ "X$?" = "X0" ]; then
- NAME_PARAM="-sname"
- NAME_HOST=""
- else
- NAME_PARAM="-name"
- echo "$NAME_ARG" | grep '@.*' > /dev/null 2>&1
- if [ "X$?" = "X0" ]; then
- NAME_HOST=`echo "${NAME_ARG}" | sed -e 's/.*\(@.*\)$/\1/'`
- else
- NAME_HOST=""
- fi
- fi
- # Extract the target cookie
- COOKIE_ARG=`grep -e '-setcookie' $RUNNER_ETC_DIR/vm.args`
- if [ -z "$COOKIE_ARG" ]; then
- echo "vm.args needs to have a -setcookie parameter."
- exit 1
- fi
- # Identify the script name
- SCRIPT=`basename $0`
- # Parse out release and erts info
- START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
- ERTS_VSN=${START_ERL% *}
- APP_VSN=${START_ERL#* }
- # Add ERTS bin dir to our path
- 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"
- internal_cmd()
- {
- $ERTS_PATH/erl -noshell $NAME_PARAM uce_ctl$NAME_HOST $COOKIE_ARG \
- -s uce_ctl \
- -dummy \
- "$@" \
- $NODE_ARG
- }
- tests()
- {
- $ERTS_PATH/erl -noshell $NAME_ARG \
- -config $RUNNER_ETC_DIR/app.config \
- -run ucengine_app \
- -eval "tests:start()."
- }
- fetch_metrics()
- {
- if [ -z $2 ];
- then
- echo "Please provide a destination folder"
- echo "$0 fetch_metrics /tmp/"
- exit 1
- fi
- NODE_UCENGINE=`echo "${NAME_ARG}" | sed -e 's/-name \(.*\)$/\1/'`
- EVAL="io:format(\"~p~n\", [rpc:call('$NODE_UCENGINE', metrics_counter, to_file, [\"$2/counter.csv\"])]), \
- io:format(\"~p~n\", [rpc:call('$NODE_UCENGINE', metrics_gauge, to_file, [\"$2/gauge.csv\"])]), \
- halt()."
- $ERTS_PATH/erl -noshell $NAME_PARAM metrics_dump$NAME_HOST $COOKIE_ARG \
- -dummy \
- -eval "$EVAL"
- }
- # Check the first argument for instructions
- case "$1" in
- --help) internal_cmd $@;;
- tests) tests $@;;
- fetch_metrics) fetch_metrics $@;;
- *) internal_cmd $@;;
- esac