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