forked from processone/tsung
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsung.sh.in
executable file
·213 lines (193 loc) · 6.08 KB
/
tsung.sh.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/usr/bin/env bash
UNAME=`uname`
case $UNAME in
"Linux")
HOST=`hostname -s 2>/dev/null`
RET=$?
if [ $RET != 0 ]; then
HOST=`hostname`
echo "WARN: hostname -s failed, use '$HOST' as hostname" > /dev/stderr
fi
;;
"SunOS") HOST=`hostname`;;
*) HOST=`hostname -s`;;
esac
INSTALL_DIR=@EXPANDED_LIBDIR@/erlang/
ERL=@ERL@
MAIN_DIR=$HOME/.tsung
LOG_DIR=$MAIN_DIR/log
LOG_OPT="log_dir \"$LOG_DIR/\""
MON_FILE="mon_file \"tsung.log\""
VERSION=@PACKAGE_VERSION@
NAMETYPE="-sname"
PROTO_DIST=" -proto_dist inet_tcp "
LISTEN_PORT=8090
USE_PARENT_PROXY=false
PGSQL_SERVER_IP=127.0.0.1
PGSQL_SERVER_PORT=5432
NAME=tsung
CONTROLLER=tsung_controller
SMP_DISABLE=true
WARM_TIME=10
MAX_PROCESS=250000
TSUNGPATH=$INSTALL_DIR/lib/tsung-$VERSION/ebin
CONTROLLERPATH=$INSTALL_DIR/lib/tsung_controller-$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 "
DEBUG_LEVEL=5
ERL_RSH=" -rsh ssh "
ERL_DIST_PORTS=" -kernel inet_dist_listen_min 64000 -kernel inet_dist_listen_max 65500 "
ERL_OPTS=" $ERL_DIST_PORTS -smp auto +P $MAX_PROCESS +A 16 +K true @ERL_OPTS@ "
COOKIE='tsung'
ERTS_RUN=`$ERL -version 2>&1 | tr -cd 0123456789.`
ERTS_BOOT=`grep erts $TSUNGPATH/../priv/tsung.rel 2> /dev/null| tr -cd 0123456789.`
stop() {
$ERL $ERL_OPTS $ERL_RSH -noshell $PROTO_DIST $NAMETYPE killer -setcookie $COOKIE -pa $TSUNGPATH -pa $CONTROLLERPATH -s tsung_controller stop_all $HOST -s init stop
}
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
}
start() {
echo "Starting Tsung"
$ERL $ERL_OPTS $ERL_RSH -noshell $PROTO_DIST $NAMETYPE $CONTROLLER -setcookie $COOKIE $BOOT_OPT \
-pa $TSUNGPATH -pa $CONTROLLERPATH \
-tsung_controller smp_disable $SMP_DISABLE \
-tsung_controller debug_level $DEBUG_LEVEL \
-tsung_controller warm_time $WARM_TIME \
-tsung_controller config_file \"$CONF_OPT_FILE\" -tsung_controller $LOG_OPT -tsung_controller $MON_FILE
}
debug() {
$ERL $ERL_OPTS $ERL_RSH $NAMETYPE $CONTROLLER $PROTO_DIST -setcookie $COOKIE $BOOT_OPT \
-pa $TSUNGPATH -pa $CONTROLLERPATH \
-tsung_controller warm_time $WARM_TIME \
-tsung_controller config_file \"$CONF_OPT_FILE\" \
-tsung_controller $LOG_OPT -tsung_controller $MON_FILE
}
version() {
echo "Tsung version $VERSION"
exit 0
}
checkconfig() {
if [ ! -e $CONF_OPT_FILE ] && [ $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 $NAMETYPE $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
}
usage() {
prog=`basename $0`
echo "Usage: $prog <options> start|stop|debug|status"
echo "Options:"
echo " -f <file> set configuration file (default is ~/.tsung/tsung.xml)"
echo " (use - for standard input)"
echo " -l <logdir> set log directory where YYYYMMDD-HHMM dirs are created (default is ~/.tsung/log/) "
echo " -i <id> set controller id (default is empty)"
echo " -r <command> set remote connector (default is ssh)"
echo " -s enable erlang smp on client nodes"
echo " -p <max> set maximum erlang processes per vm (default is 250000)"
echo " -m <file> write monitoring output on this file (default is tsung.log)"
echo " (use - for standard output)"
echo " -F use long names (FQDN) for erlang nodes"
echo " -w warmup delay (default is 10 sec)"
echo " -v print version information and exit"
echo " -6 use IPv6 for Tsung internal communications"
echo " -h display this help and exit"
exit
}
while getopts "6vhf:l:d:r:i:Fsw:m:p:" Option
do
case $Option in
f) CONF_OPT_FILE=$OPTARG;;
l) # must add absolute path
echo "$OPTARG" | grep -q "^/"
RES=$?
if [ "$RES" == 0 ]; then
LOG_OPT="log_dir \"$OPTARG/\" "
else
LOG_OPT="log_dir \"$PWD/$OPTARG/\" "
fi
;;
m) MON_FILE="mon_file \"$OPTARG\"";;
d) DEBUG_LEVEL=$OPTARG;;
p) MAX_PROCESS=$OPTARG;;
r) ERL_RSH=" -rsh $OPTARG ";;
6) PROTO_DIST=" -proto_dist inet6_tcp ";;
F) NAMETYPE="-name";;
w) WARM_TIME=$OPTARG;;
s) SMP_DISABLE="false";;
v) version;;
i) ID=$OPTARG
COOKIE=$COOKIE"_"$ID
CONTROLLER=$CONTROLLER"_"$ID
;;
h) usage;;
*) usage ;;
esac
done
shift $(($OPTIND - 1))
case $1 in
start)
checkconfig
checkversion
maindir
logdir
start
;;
boot)
checkversion
;;
debug)
checkconfig
checkversion
maindir
logdir
debug
;;
stop)
stop
;;
status)
status
;;
*)
usage $0
;;
esac