Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 209 lines (188 sloc) 5.684 kb
4c0948f @nniclausse split tsung command into tsung and tsung-recorder (TSUN-113)
nniclausse authored
1 #!/usr/bin/env bash
2
3 UNAME=`uname`
4 case $UNAME in
5 "Linux") HOST=`hostname -s`;;
6 "SunOS") HOST=`hostname`;;
7 *) HOST=`hostname -s`;;
8 esac
9
10 INSTALL_DIR=@prefix@/lib/erlang/
11 ERL=@ERL@
12 MAIN_DIR=$HOME/.tsung
13 LOG_DIR=$MAIN_DIR/log
14 LOG_OPT="log_file \"$LOG_DIR/tsung.log\""
15 VERSION=@PACKAGE_VERSION@
16 NAMETYPE="-sname"
17
18 LISTEN_PORT=8090
19 USE_PARENT_PROXY=false
20 PGSQL_SERVER_IP=127.0.0.1
21 PGSQL_SERVER_PORT=5432
22 NAME=tsung
23 RECORDER=tsung_recorder
24
25 TSUNGPATH=$INSTALL_DIR/lib/tsung-$VERSION/ebin
26 RECORDERPATH=$INSTALL_DIR/lib/tsung_recorder-$VERSION/ebin
27
28 CONF_OPT_FILE="$HOME/.tsung/tsung.xml"
29 BOOT_OPT="-boot $INSTALL_DIR/lib/tsung_controller-$VERSION/priv/tsung_controller -boot_var TSUNGPATH $INSTALL_DIR "
30 REC_BOOT_OPT="-boot $INSTALL_DIR/lib/tsung_recorder-$VERSION/priv/tsung_recorder -boot_var TSUNGPATH $INSTALL_DIR "
31 DEBUG_LEVEL=5
32 RECORDER_PLUGIN="http"
33 ERL_RSH=" -rsh ssh "
34 ERL_OPTS=" -smp auto +P 250000 +A 16 +K true @ERL_OPTS@ "
35 COOKIE='tsung'
36 ERTS_RUN=`$ERL -version 2>&1 | tr -cd 0123456789.`
37 ERTS_BOOT=`grep erts $TSUNGPATH/../priv/tsung.rel 2> /dev/null| tr -cd 0123456789.`
38
39 stop() {
40 $ERL $ERL_OPTS $ERL_RSH -noshell $NAMETYPE killer -setcookie $COOKIE -pa $TSUNGPATH -pa $RECORDERPATH -s tsung_recorder stop_all $HOST -s init stop
41 RET=$?
42 if [ $RET == 1 ]; then
43 echo "FAILED"
44 else
45 echo "[OK]"
46 rm $PIDFILE
47 fi
48 }
49
50 status() {
51 PIDFILE="/tmp/tsung_recorder.pid"
52 if [ -f $PIDFILE ]; then
53 echo "Tsung recorder started [OK]"
54 else
55 echo "Tsung recorder not started "
56 fi
57 }
58
59 checkversion() {
60 if [ $ERTS_RUN != $ERTS_BOOT ]
61 then
62 echo "Erlang version has changed ! [$ERTS_BOOT] != [$ERTS_RUN]"
63 echo "Must create new boot files (you may have to run this one time as root ! )"
64 makebootfiles
65 fi
66 }
67
68 makebootfiles() {
69 echo "creating boot file for tsung_recorder application"
70 cd $RECORDERPATH/..
71 $ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
72 }
73
74 start() {
75 echo "Starting Tsung recorder on port $LISTEN_PORT"
76 $ERL $ERL_OPTS $ERL_RSH -noshell $NAMETYPE $RECORDER -setcookie $COOKIE $REC_BOOT_OPT \
77 -pa $TSUNGPATH -pa $RECORDERPATH -pa $CONTROLLERPATH \
78 -tsung_recorder debug_level $DEBUG_LEVEL \
79 -tsung_recorder $LOG_OPT \
80 -tsung_recorder parent_proxy $USE_PARENT_PROXY \
81 -tsung_recorder plugin ts_proxy_$RECORDER_PLUGIN \
82 -tsung_recorder proxy_log_file \"$MAIN_DIR/tsung_recorder.xml\" \
83 -tsung_recorder pgsql_server \"${PGSQL_SERVER_IP}\" \
84 -tsung_recorder pgsql_port ${PGSQL_SERVER_PORT} \
85 -tsung_recorder proxy_listen_port $LISTEN_PORT &
86 echo $! > /tmp/tsung_recorder.pid
87 }
88
89 version() {
90 echo "Tsung Recorder version $VERSION"
91 exit 0
92 }
93
94 checkconfig() {
95 if [ ! -e $CONF_OPT_FILE ]
96 then
97 echo "Config file $CONF_OPT_FILE doesn't exist, aborting !"
98 exit 1
99 fi
100 }
101
102 maindir() {
103 if [ ! -d $MAIN_DIR ]
104 then
105 echo "Creating local Tsung directory $MAIN_DIR"
106 mkdir $MAIN_DIR
107 fi
108 }
109
110 logdir() {
111 if [ ! -d $LOG_DIR ]
112 then
113 echo "Creating Tsung log directory $LOG_DIR"
114 mkdir $LOG_DIR
115 fi
116 }
117
118 record_tag() {
119 shift
120 SNAME=tsung_recordtag
121 $ERL -noshell $NAMETYPE $SNAME -setcookie $COOKIE -pa $TSUNGPATH -pa $RECORDERPATH -run ts_proxy_recorder recordtag $HOST "$*" -s init stop
122 }
123
124 checkrunning(){
125 if [ -f $PIDFILE ]; then
126 CURPID=`cat $PIDFILE`
127 if kill -0 $CURPID 2> /dev/null ; then
128 echo "Can't start: Tsung recorder already running !"
129 exit 1
130 fi
131 fi
132 }
133
134 usage() {
135 prog=`basename $0`
136 echo "Usage: $prog <options> start|stop|restart"
137 echo "Options:"
138 echo " -p <plugin> plugin used for the recorder"
139 echo " available: http, pgsql,webdav (default is http)"
140 echo " -L <port> listening port for the recorder (default is 8090)"
141 echo " -I <IP> for the pgsql recorder (or parent proxy): server IP"
142 echo " (default is 127.0.0.1)"
143 echo " -P <port> for the pgsql recorder (or parent proxy): server port"
144 echo " (default is 5432)"
145 echo " -u for the http recorder: use a parent proxy"
146 echo " -d <level> set log level from 0 to 7 (default is 5)"
147 echo " -v print version information and exit"
148 echo " -h display this help and exit"
149 exit
150 }
151
152 while getopts "hvf:p:l:d:r:i:P:L:I:u:" Option
153 do
154 case $Option in
155 f) CONF_OPT_FILE=$OPTARG;;
156 l) # must add absolute path
157 echo "$OPTARG" | grep -q "^/"
158 RES=$?
159 if [ "$RES" == 0 ]; then
160 LOG_OPT="log_file \"$OPTARG\" "
161 else
162 LOG_OPT="log_file \"$PWD/$OPTARG\" "
163 fi
164 ;;
165 d) DEBUG_LEVEL=$OPTARG;;
166 p) RECORDER_PLUGIN=$OPTARG;;
167 I) PGSQL_SERVER_IP=$OPTARG;;
168 u) USE_PARENT_PROXY=true;;
169 P) PGSQL_SERVER_PORT=$OPTARG;;
170 L) LISTEN_PORT=$OPTARG;;
171 v) version;;
172 h) usage;;
173 *) usage ;;
174 esac
175 done
176 shift $(($OPTIND - 1))
177
178 case $1 in
179 start)
180 PIDFILE="/tmp/tsung_recorder.pid"
181 checkversion
182 maindir
183 logdir
184 checkrunning
185 recorder
186 ;;
187
188 record_tag)
189 record_tag $*
190 ;;
191 boot)
192 checkversion
193 ;;
194 stop)
195 PIDFILE="/tmp/tsung_recorder.pid"
196 stop_recorder
197 ;;
198 status)
199 recorder_status
200 ;;
201 restart)
202 stop
203 start
204 ;;
205 *)
206 usage $0
207 ;;
208 esac
Something went wrong with that request. Please try again.