Skip to content
Newer
Older
100755 260 lines (229 sloc) 6.5 KB
c8b5ae0 @nniclausse use env
nniclausse authored
1 #!/usr/bin/env bash
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
2
ea00068 @nniclausse use bash; solaris does not like 'hostname -s' (jasonwtucker@gmail.com)
nniclausse authored
3 UNAME=`uname`
4 case $UNAME in
3027f82 @nniclausse argh
nniclausse authored
5 "Linux") HOST=`hostname -s`;;
6 "SunOS") HOST=`hostname`;;
7 *) HOST=`hostname -s`;;
ea00068 @nniclausse use bash; solaris does not like 'hostname -s' (jasonwtucker@gmail.com)
nniclausse authored
8 esac
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
9
13dfdfd @nniclausse update configure & Makefile
nniclausse authored
10 INSTALL_DIR=@prefix@/lib/erlang/
11 ERL=@ERL@
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
12 MAIN_DIR=$HOME/.tsung
76b47d6 @nniclausse save session in main directory instead of log
nniclausse authored
13 LOG_DIR=$MAIN_DIR/log
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
14 LOG_OPT="log_file \"$LOG_DIR/tsung.log\""
13dfdfd @nniclausse update configure & Makefile
nniclausse authored
15 VERSION=@PACKAGE_VERSION@
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
16
17 LISTEN_PORT=8090
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
18 USE_PARENT_PROXY=false
eff2fce @nniclausse listening port and dest IP (for pgsql recorder) can be set at runtime…
nniclausse authored
19 PGSQL_SERVER_IP=127.0.0.1
af90734 @nniclausse pgsql recorder: server port can be set with -P (listening port option…
nniclausse authored
20 PGSQL_SERVER_PORT=5432
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
21 NAME=tsung
22 CONTROLLER=tsung_controller
23 RECORDER=tsung_recorder
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
24
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
25 TSUNGPATH=$INSTALL_DIR/lib/tsung-$VERSION/ebin
26 CONTROLLERPATH=$INSTALL_DIR/lib/tsung_controller-$VERSION/ebin
27 RECORDERPATH=$INSTALL_DIR/lib/tsung_recorder-$VERSION/ebin
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
28
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
29 CONF_OPT_FILE="$HOME/.tsung/tsung.xml"
30 BOOT_OPT="-boot $INSTALL_DIR/lib/tsung_controller-$VERSION/priv/tsung_controller -boot_var TSUNGPATH $INSTALL_DIR "
31 REC_BOOT_OPT="-boot $INSTALL_DIR/lib/tsung_recorder-$VERSION/priv/tsung_recorder -boot_var TSUNGPATH $INSTALL_DIR "
a68c3e6 @nniclausse initial debug level also for controller
nniclausse authored
32 DEBUG_LEVEL=5
ad4f1ed @nniclausse refactoring of recorder: add plugin architecture for other protocols …
nniclausse authored
33 RECORDER_PLUGIN="http"
95fb173 @nniclausse add -r option to set the command for starting nodes on remote host (s…
nniclausse authored
34 ERL_RSH=" -rsh ssh "
7e7fa2f @nniclausse add kernel-poll support (TSUN-45)
nniclausse authored
35 ERL_OPTS=" -smp auto +A 2 +K true @ERL_OPTS@ "
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
36 COOKIE='tsung'
12f1e4d @nniclausse fix tr args for solaris
nniclausse authored
37 ERTS_RUN=`$ERL -version 2>&1 | tr -cd 0123456789.`
38 ERTS_BOOT=`grep erts $TSUNGPATH/../priv/tsung.rel | tr -cd 0123456789.`
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
39
40 stop() {
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
41 $ERL $ERL_OPTS $ERL_RSH -noshell -sname killer -setcookie $COOKIE -pa $TSUNGPATH -pa $CONTROLLERPATH -s tsung_controller stop_all $HOST -s init stop
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
42 }
43
44 stop_recorder() {
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
45 $ERL $ERL_OPTS $ERL_RSH -noshell -sname killer -setcookie $COOKIE -pa $TSUNGPATH -pa $RECORDERPATH -s tsung_recorder stop_all $HOST -s init stop
33626a6 @nniclausse ability to record a string with 'record_tag' (TSUN-52)
nniclausse authored
46 RET=$?
47 if [ $RET == 1 ]; then
48 echo "FAILED"
49 else
50 echo "[OK]"
51 rm $PIDFILE
52 fi
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
53 }
54
c65d43c @nniclausse fix output msg; fix usage.
nniclausse authored
55 recorder_status() {
56 PIDFILE="/tmp/tsung_recorder.pid"
57 if [ -f $PIDFILE ]; then
58 echo "Tsung recorder started [OK]"
59 else
60 echo "Tsung recorder not started "
61 fi
62 }
63
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
64 checkversion() {
0992b82 @nniclausse check if recorder is already running
nniclausse authored
65 if [ $ERTS_RUN != $ERTS_BOOT ]
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
66 then
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
67 echo "Erlang version has changed ! [$ERTS_BOOT] != [$ERTS_RUN]"
68 echo "Must create new boot files (you may have to run this one time as root ! )"
69 makebootfiles
0992b82 @nniclausse check if recorder is already running
nniclausse authored
70 fi
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
71 }
72
73 makebootfiles() {
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
74 cd $TSUNGPATH/..
75 echo "creating boot file for tsung application"
76 $ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
77 cd $CONTROLLERPATH/..
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
78 echo "creating boot file for tsung_controller application"
79 $ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
80 echo "creating boot file for tsung_recorder application"
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
81 cd $RECORDERPATH/..
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
82 $ERL $ERL_OPTS -noshell -pa $TSUNGPATH -s builder go -s init stop > /dev/null
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
83 }
84
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
85 start() {
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
86 echo "Starting Tsung"
c3bd40d @nniclausse do not detached tsunami with start
nniclausse authored
87 $ERL $ERL_OPTS $ERL_RSH -noshell -sname $CONTROLLER -setcookie $COOKIE $BOOT_OPT \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
88 -pa $TSUNGPATH -pa $CONTROLLERPATH \
a68c3e6 @nniclausse initial debug level also for controller
nniclausse authored
89 -tsung_controller debug_level $DEBUG_LEVEL \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
90 -tsung_controller config_file \"$CONF_OPT_FILE\" -tsung_controller $LOG_OPT
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
91 }
92
93 recorder() {
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
94 echo "Starting Tsung recorder on port $LISTEN_PORT"
0992b82 @nniclausse check if recorder is already running
nniclausse authored
95 $ERL $ERL_OPTS $ERL_RSH -noshell -sname $RECORDER -setcookie $COOKIE $REC_BOOT_OPT \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
96 -pa $TSUNGPATH -pa $RECORDERPATH -pa $CONTROLLERPATH \
a68c3e6 @nniclausse initial debug level also for controller
nniclausse authored
97 -tsung_recorder debug_level $DEBUG_LEVEL \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
98 -tsung_recorder $LOG_OPT \
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
99 -tsung_recorder parent_proxy $USE_PARENT_PROXY \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
100 -tsung_recorder plugin ts_proxy_$RECORDER_PLUGIN \
101 -tsung_recorder proxy_log_file \"$MAIN_DIR/tsung_recorder.xml\" \
eff2fce @nniclausse listening port and dest IP (for pgsql recorder) can be set at runtime…
nniclausse authored
102 -tsung_recorder pgsql_server \"${PGSQL_SERVER_IP}\" \
af90734 @nniclausse pgsql recorder: server port can be set with -P (listening port option…
nniclausse authored
103 -tsung_recorder pgsql_port ${PGSQL_SERVER_PORT} \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
104 -tsung_recorder proxy_listen_port $LISTEN_PORT &
105 echo $! > /tmp/tsung_recorder.pid
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
106 }
107
7fbd71d @nniclausse check if config file exist
nniclausse authored
108 debug() {
95fb173 @nniclausse add -r option to set the command for starting nodes on remote host (s…
nniclausse authored
109 $ERL $ERL_OPTS $ERL_RSH -sname $CONTROLLER -setcookie $COOKIE $BOOT_OPT \
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
110 -pa $TSUNGPATH -pa $CONTROLLERPATH \
111 -tsung_controller config_file \"$CONF_OPT_FILE\" \
112 -tsung_controller $LOG_OPT
7fbd71d @nniclausse check if config file exist
nniclausse authored
113 }
114
13dfdfd @nniclausse update configure & Makefile
nniclausse authored
115 version() {
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
116 echo "Tsung version $VERSION"
13dfdfd @nniclausse update configure & Makefile
nniclausse authored
117 }
118
7fbd71d @nniclausse check if config file exist
nniclausse authored
119 checkconfig() {
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
120 if [ ! -e $CONF_OPT_FILE ]
121 then
122 echo "Config file $CONF_OPT_FILE doesn't exist, aborting !"
123 exit 1
124 fi
7fbd71d @nniclausse check if config file exist
nniclausse authored
125 }
126
1ffd1ec @nniclausse add configure scripts to detect erlang installation directory and com…
nniclausse authored
127 maindir() {
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
128 if [ ! -d $MAIN_DIR ]
129 then
130 echo "Creating local Tsung directory $MAIN_DIR"
131 mkdir $MAIN_DIR
132 fi
1ffd1ec @nniclausse add configure scripts to detect erlang installation directory and com…
nniclausse authored
133 }
7fbd71d @nniclausse check if config file exist
nniclausse authored
134
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
135 logdir() {
136 if [ ! -d $LOG_DIR ]
137 then
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
138 echo "Creating Tsung log directory $LOG_DIR"
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
139 mkdir $LOG_DIR
140 fi
141 }
142
143 status() {
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
144 SNAME=tsung_status_$RANDOM
145 $ERL -noshell -sname $SNAME -setcookie $COOKIE -pa $TSUNGPATH -pa $CONTROLLERPATH -s tsung_controller status $HOST -s init stop
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
146 }
147
33626a6 @nniclausse ability to record a string with 'record_tag' (TSUN-52)
nniclausse authored
148 record_tag() {
149 shift
150 SNAME=tsung_recordtag
151 $ERL -noshell -sname $SNAME -setcookie $COOKIE -pa $TSUNGPATH -pa $RECORDERPATH -run ts_proxy_recorder recordtag $HOST "$*" -s init stop
152 }
153
0992b82 @nniclausse check if recorder is already running
nniclausse authored
154 checkrunning_controller() {
155 RES=`status`
c65d43c @nniclausse fix output msg; fix usage.
nniclausse authored
156 if [ "$RES" != "Tsung is not started" ]; then
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
157 echo "Tsung is already running, exit."
0992b82 @nniclausse check if recorder is already running
nniclausse authored
158 exit 1
159 fi
160 }
161
162 checkrunning(){
163 if [ -f $PIDFILE ]; then
164 CURPID=`cat $PIDFILE`
165 if kill -0 $CURPID 2> /dev/null ; then
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
166 echo "Can't start: Tsung recorder already running !"
0992b82 @nniclausse check if recorder is already running
nniclausse authored
167 exit 1
168 fi
169 fi
170 }
171
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
172 usage() {
c65d43c @nniclausse fix output msg; fix usage.
nniclausse authored
173 prog=`basename $0`
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
174 echo "$prog <options> start|stop|restart|debug|status|recorder|stop_recorder|version"
c65d43c @nniclausse fix output msg; fix usage.
nniclausse authored
175 exit
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
176 }
177
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
178 while getopts ":f:p:l:d:r:i:P:L:I:u" Option
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
179 do
180 case $Option in
7fbd71d @nniclausse check if config file exist
nniclausse authored
181 f) CONF_OPT_FILE=$OPTARG;;
459db7e @nniclausse absolute path needed for logfile name (fix TSUN-57)
nniclausse authored
182 l) # must add absolute path
183 echo "$OPTARG" | grep -q "^/"
184 RES=$?
185 if [ "$RES" == 0 ]; then
186 LOG_OPT="log_file \"$OPTARG\" "
187 else
188 LOG_OPT="log_file \"$PWD/$OPTARG\" "
189 fi
190 ;;
a68c3e6 @nniclausse initial debug level also for controller
nniclausse authored
191 d) DEBUG_LEVEL=$OPTARG;;
95fb173 @nniclausse add -r option to set the command for starting nodes on remote host (s…
nniclausse authored
192 r) ERL_RSH=" -rsh $OPTARG ";;
ad4f1ed @nniclausse refactoring of recorder: add plugin architecture for other protocols …
nniclausse authored
193 p) RECORDER_PLUGIN=$OPTARG;;
af90734 @nniclausse pgsql recorder: server port can be set with -P (listening port option…
nniclausse authored
194 I) PGSQL_SERVER_IP=$OPTARG;;
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
195 u) USE_PARENT_PROXY=true;;
af90734 @nniclausse pgsql recorder: server port can be set with -P (listening port option…
nniclausse authored
196 P) PGSQL_SERVER_PORT=$OPTARG;;
197 L) LISTEN_PORT=$OPTARG;;
f2c04e9 @nniclausse argh, stupid typo
nniclausse authored
198 *) usage ;;
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
199 esac
3493e62 @nniclausse add parent proxy support for http: first step (TSUN-37)
nniclausse authored
200 done
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
201 shift $(($OPTIND - 1))
202
203 case $1 in
204 start)
0992b82 @nniclausse check if recorder is already running
nniclausse authored
205 checkconfig
206 checkversion
1ffd1ec @nniclausse add configure scripts to detect erlang installation directory and com…
nniclausse authored
207 maindir
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
208 logdir
209 start
210 ;;
211 recorder)
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
212 PIDFILE="/tmp/tsung_recorder.pid"
0992b82 @nniclausse check if recorder is already running
nniclausse authored
213 checkversion
1ffd1ec @nniclausse add configure scripts to detect erlang installation directory and com…
nniclausse authored
214 maindir
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
215 logdir
0992b82 @nniclausse check if recorder is already running
nniclausse authored
216 checkrunning
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
217 recorder
218 ;;
219
33626a6 @nniclausse ability to record a string with 'record_tag' (TSUN-52)
nniclausse authored
220 record_tag)
221 record_tag $*
222 ;;
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
223 boot)
0992b82 @nniclausse check if recorder is already running
nniclausse authored
224 checkversion
225 ;;
0964e94 @nniclausse detect version of erlang in boot script and rebuild them if needed
nniclausse authored
226
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
227 debug)
0992b82 @nniclausse check if recorder is already running
nniclausse authored
228 checkconfig
229 checkversion
1ffd1ec @nniclausse add configure scripts to detect erlang installation directory and com…
nniclausse authored
230 maindir
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
231 logdir
232 debug
233 ;;
234
235 stop)
236 stop
237 ;;
238 stop_recorder)
5345a3b @nniclausse rename idx-tsunami to tsung step 3
nniclausse authored
239 PIDFILE="/tmp/tsung_recorder.pid"
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
240 stop_recorder
241 ;;
242
243 status)
c65d43c @nniclausse fix output msg; fix usage.
nniclausse authored
244 recorder_status
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
245 status
246 ;;
247
248 restart)
249 stop
250 start
251 ;;
13dfdfd @nniclausse update configure & Makefile
nniclausse authored
252 version)
253 version
254 ;;
748e9e0 @nniclausse major source reorganisation to ease debian packaging
nniclausse authored
255
256 *)
257 usage $0
258 ;;
259 esac
Something went wrong with that request. Please try again.