Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: af90734fa9
Fetching contributors…

Cannot retrieve contributors at this time

executable file 234 lines (204 sloc) 5.878 kb
#!/usr/bin/env bash
UNAME=`uname`
case $UNAME in
"Linux") HOST=`hostname -s`;;
"SunOS") HOST=`hostname`;;
*) HOST=`hostname -s`;;
esac
INSTALL_DIR=@prefix@/lib/erlang/
ERL=@ERL@
MAIN_DIR=$HOME/.tsung
LOG_DIR=$MAIN_DIR/log
LOG_OPT="log_file \"$LOG_DIR/tsung.log\""
VERSION=@PACKAGE_VERSION@
LISTEN_PORT=8090
PGSQL_SERVER_IP=127.0.0.1
PGSQL_SERVER_PORT=5432
NAME=tsung
CONTROLLER=tsung_controller
RECORDER=tsung_recorder
TSUNGPATH=$INSTALL_DIR/lib/tsung-$VERSION/ebin
CONTROLLERPATH=$INSTALL_DIR/lib/tsung_controller-$VERSION/ebin
RECORDERPATH=$INSTALL_DIR/lib/tsung_recorder-$VERSION/ebin
CONF_OPT_FILE="$HOME/.tsung/tsung.xml"
BOOT_OPT="-boot $INSTALL_DIR/lib/tsung_controller-$VERSION/priv/tsung_controller -boot_var TSUNGPATH $INSTALL_DIR "
REC_BOOT_OPT="-boot $INSTALL_DIR/lib/tsung_recorder-$VERSION/priv/tsung_recorder -boot_var TSUNGPATH $INSTALL_DIR "
DEBUG_LEVEL=5
RECORDER_PLUGIN="http"
ERL_RSH=" -rsh ssh "
ERL_OPTS=" +A 1 @ERL_OPTS@ "
COOKIE='tsung'
ERTS_RUN=`$ERL -version 2>&1 | tr -cd 0123456789.`
ERTS_BOOT=`grep erts $TSUNGPATH/../priv/tsung.rel | tr -cd 0123456789.`
stop() {
$ERL $ERL_OPTS $ERL_RSH -noshell -sname killer -setcookie $COOKIE -pa $TSUNGPATH -pa $CONTROLLERPATH -s tsung_controller stop_all $HOST -s init stop
}
stop_recorder() {
$ERL $ERL_OPTS $ERL_RSH -noshell -sname killer -setcookie $COOKIE -pa $TSUNGPATH -pa $RECORDERPATH -s tsung_recorder stop_all $HOST -s init stop
rm $PIDFILE
}
recorder_status() {
PIDFILE="/tmp/tsung_recorder.pid"
if [ -f $PIDFILE ]; then
echo "Tsung recorder started [OK]"
else
echo "Tsung recorder not started "
fi
}
checkversion() {
if [ $ERTS_RUN != $ERTS_BOOT ]
then
echo "Erlang version has changed ! [$ERTS_BOOT] != [$ERTS_RUN]"
echo "Must create new boot files (you may have to run this one time as root ! )"
makebootfiles
fi
}
makebootfiles() {
cd $TSUNGPATH/..
echo "creating boot file for tsung application"
$ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
cd $CONTROLLERPATH/..
echo "creating boot file for tsung_controller application"
$ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
echo "creating boot file for tsung_recorder application"
cd $RECORDERPATH/..
$ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
}
start() {
echo "Starting Tsung"
$ERL $ERL_OPTS $ERL_RSH -noshell -sname $CONTROLLER -setcookie $COOKIE $BOOT_OPT \
-pa $TSUNGPATH -pa $CONTROLLERPATH \
-tsung_controller debug_level $DEBUG_LEVEL \
-tsung_controller config_file \"$CONF_OPT_FILE\" -tsung_controller $LOG_OPT
}
recorder() {
echo "Starting Tsung recorder on port $LISTEN_PORT"
$ERL $ERL_OPTS $ERL_RSH -noshell -sname $RECORDER -setcookie $COOKIE $REC_BOOT_OPT \
-pa $TSUNGPATH -pa $RECORDERPATH -pa $CONTROLLERPATH \
-tsung_recorder debug_level $DEBUG_LEVEL \
-tsung_recorder $LOG_OPT \
-tsung_recorder plugin ts_proxy_$RECORDER_PLUGIN \
-tsung_recorder proxy_log_file \"$MAIN_DIR/tsung_recorder.xml\" \
-tsung_recorder pgsql_server \"${PGSQL_SERVER_IP}\" \
-tsung_recorder pgsql_port ${PGSQL_SERVER_PORT} \
-tsung_recorder proxy_listen_port $LISTEN_PORT &
echo $! > /tmp/tsung_recorder.pid
}
debug() {
$ERL $ERL_OPTS $ERL_RSH -sname $CONTROLLER -setcookie $COOKIE $BOOT_OPT \
-pa $TSUNGPATH -pa $CONTROLLERPATH \
-tsung_controller config_file \"$CONF_OPT_FILE\" \
-tsung_controller $LOG_OPT
}
version() {
echo "Tsung version $VERSION"
}
checkconfig() {
if [ ! -e $CONF_OPT_FILE ]
then
echo "Config file $CONF_OPT_FILE doesn't exist, aborting !"
exit 1
fi
}
maindir() {
if [ ! -d $MAIN_DIR ]
then
echo "Creating local Tsung directory $MAIN_DIR"
mkdir $MAIN_DIR
fi
}
logdir() {
if [ ! -d $LOG_DIR ]
then
echo "Creating Tsung log directory $LOG_DIR"
mkdir $LOG_DIR
fi
}
status() {
SNAME=tsung_status_$RANDOM
$ERL -noshell -sname $SNAME -setcookie $COOKIE -pa $TSUNGPATH -pa $CONTROLLERPATH -s tsung_controller status $HOST -s init stop
}
checkrunning_controller() {
RES=`status`
if [ "$RES" != "Tsung is not started" ]; then
echo "Tsung is already running, exit."
exit 1
fi
}
checkrunning(){
if [ -f $PIDFILE ]; then
CURPID=`cat $PIDFILE`
if kill -0 $CURPID 2> /dev/null ; then
echo "Can't start: Tsung recorder already running !"
exit 1
fi
fi
}
usage() {
prog=`basename $0`
echo "$prog start|stop|restart|debug|status|recorder|stop_recorder|version"
exit
}
while getopts ":f:p:l:d:r:i:P:L:I:" Option
do
case $Option in
f) CONF_OPT_FILE=$OPTARG;;
l) LOG_OPT="log_file \"$OPTARG\" ";;
d) DEBUG_LEVEL=$OPTARG;;
r) ERL_RSH=" -rsh $OPTARG ";;
p) RECORDER_PLUGIN=$OPTARG;;
I) PGSQL_SERVER_IP=$OPTARG;;
P) PGSQL_SERVER_PORT=$OPTARG;;
L) LISTEN_PORT=$OPTARG;;
*) usage ;;
esac
done
shift $(($OPTIND - 1))
case $1 in
start)
checkconfig
checkversion
maindir
logdir
start
;;
recorder)
PIDFILE="/tmp/tsung_recorder.pid"
checkversion
maindir
logdir
checkrunning
recorder
;;
boot)
checkversion
;;
debug)
checkconfig
checkversion
maindir
logdir
debug
;;
stop)
stop
;;
stop_recorder)
PIDFILE="/tmp/tsung_recorder.pid"
stop_recorder
;;
status)
recorder_status
status
;;
restart)
stop
start
;;
version)
version
;;
*)
usage $0
;;
esac
Jump to Line
Something went wrong with that request. Please try again.