forked from sjug/centos-stress
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocker-entrypoint.sh
executable file
·162 lines (133 loc) · 4.13 KB
/
docker-entrypoint.sh
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
#!/bin/bash
# Some parts written for /bin/bash, see arrays in jmeter)
# Entrypoint script for Load Generator Docker Image
ProgramName=${0##*/}
# Global variables
url_gun_ws="http://${GUN}:9090"
gw_hex=$(grep ^eth0 /proc/net/route | head -1 | awk '{print $3}')
#gateway=$(/sbin/ip route|awk '/default/ { print $3 }') # sometimes there is no /sbin/ip ...
gateway=$(printf "%d.%d.%d.%d" 0x${gw_hex:6:2} 0x${gw_hex:4:2} 0x${gw_hex:2:2} 0x${gw_hex:0:2})
fail() {
echo $@ >&2
}
warn() {
fail "$ProgramName: $@"
}
die() {
local err=$1
shift
fail "$ProgramName: $@"
exit $err
}
usage() {
cat <<EOF 1>&2
Usage: $ProgramName
EOF
}
have_server() {
local server="$1"
if test "${server}" = "127.0.0.1" || test "${server}" = "" ; then
# server not defined
return 1
fi
}
# Wait for all the pods to be in the Running state
synchronize_pods() {
have_server "${GUN}" || return
while [ -z $(curl -s "${url_gun_ws}") ] ; do
sleep 5
fail "${url_gun_ws} not ready"
done
}
# basic checks for toybox/busybox/coreutils timeout
define_timeout_bin() {
test "${RUN_TIMEOUT}" || return # timeout empty, do not define it and just return
timeout -t 0 /bin/sleep 0 >/dev/null 2>&1
case $? in
0) # we have a busybox timeout with '-t' option for number of seconds
timeout="timeout -t ${RUN_TIMEOUT}"
;;
1) # we have toybox's timeout without the '-t' option for number of seconds
timeout="timeout ${RUN_TIMEOUT}"
;;
125) # we have coreutil's timeout without the '-t' option for number of seconds
timeout="timeout ${RUN_TIMEOUT}"
;;
*) # couldn't find timeout or unknown version
warn "running without timeout"
timeout=""
;;
esac
}
timeout_exit_status() {
local err="${1:-$?}"
case $err in
124) # coreutil's return code for timeout
return 0
;;
143) # busybox's return code for timeout with default signal TERM
return 0
;;
*) return $err
esac
}
main() {
define_timeout_bin
case "${RUN}" in
stress)
synchronize_pods
[ "${STRESS_CPU}" ] && STRESS_CPU="--cpu ${STRESS_CPU}"
$timeout \
stress ${STRESS_CPU}
$(timeout_exit_status) || die $? "${RUN} failed: $?"
;;
slstress)
local slstress_log=/tmp/${HOSTNAME}-${gateway}.log
synchronize_pods
$timeout \
slstress \
-l ${LOGGING_LINE_LENGTH} \
-w \
${LOGGING_DELAY} > ${slstress_log}
$(timeout_exit_status) || die $? "${RUN} failed: $?"
if have_server "${PBENCH_HOST}" ; then
scp -p ${slstress_log} ${PBENCH_HOST}:${PBENCH_DIR}
fi
;;
logger)
local slstress_log=/tmp/${HOSTNAME}-${gateway}.log
synchronize_pods
$timeout \
/usr/local/bin/logger.sh
$(timeout_exit_status) || die $? "${RUN} failed: $?"
;;
jmeter)
IFS=$'\n'
# Massage the host data passed in from OSE
TARGET=($(echo $TARGET_HOST | sed 's/\:/\n/g'))
TARGET_HOST="$(echo $TARGET_HOST | sed 's/\:/\ /g')"
NUM="$(echo $TARGET_HOST | wc -w)"
# JMeter constant throughput times wants TPM
((JMETER_TPS*=60))
# Add router IP & hostnames to hosts file
[ "${ROUTER_IP}" ] && echo "${ROUTER_IP} ${TARGET_HOST}" >> /etc/hosts
# Wait for Cluster Loader start signal webservice
synchronize_pods
results_filename=jmeter-"${HOSTNAME}"-"$(date +%y%m%d%H%M)"
# Call JMeter packed with ENV vars
jmeter -n -t test.jmx -Jnum=${NUM} -Jramp=${JMETER_RAMP} \
-Jduration=${RUN_TIME} -Jtpm=${JMETER_TPS} -Jipaddr1=${TARGET[0]} \
-Jipaddr2=${TARGET[1]} -Jipaddr3=${TARGET[2]} -Jipaddr4=${TARGET[3]} \
-Jipaddr5=${TARGET[4]} -Jipaddr6=${TARGET[5]} -Jipaddr7=${TARGET[6]} \
-Jipaddr8=${TARGET[7]} -Jipaddr9=${TARGET[8]} -Jport=${TARGET_PORT} \
-Jresults_file="${results_filename}".jtl -l "${results_filename}".jtl \
-j "${results_filename}".log -Jgun="${GUN}" || die $? "${RUN} failed: $?"
have_server "${PBENCH_HOST}" && scp -p *.jtl *.log *.png ${PBENCH_HOST}:${PBENCH_DIR}
;;
*)
die 1 "Need to specify what to run."
;;
esac
timeout_exit_status
}
main