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