forked from asmuth-archive/sqltap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bootup.sh
executable file
·100 lines (84 loc) · 2.57 KB
/
bootup.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
#!/bin/bash
set -e
SQLTAP_JARFILE="/usr/lib/sqltap.jar"
if [[ $SCHEMA_URL == http* ]]; then
curl -sL $SCHEMA_URL -o "${SQLTAP_SCHEMA}"
fi
require_arg() {
local name="$1"
local val="${!name}"
echo "${name}: ${val}"
if [[ "${val}" == "" ]]; then
echo "Error. Required argument ${name} missing." 1>&2
exit 1
fi
}
require_args() {
while [[ $# -ne 0 ]]; do
require_arg $1
shift
done
}
require_args SQLTAP_SCHEMA \
MYSQL_PORT \
SQLTAP_HTTP_PORT \
SQLTAP_THREADS \
SCHEMA_URL \
MYSQL_HOST \
MYSQL_PORT \
MYSQL_USER \
MYSQL_DATABASE \
MYSQL_NUMCONNS \
MYSQL_QUEUELEN \
JMX_PORT \
RMI_BIND \
JAVA_XMX \
CACHE_BACKEND
opts=""
opts="$opts --config ${SQLTAP_SCHEMA}"
opts="$opts --http ${SQLTAP_HTTP_PORT}"
opts="$opts --disable-keepalive"
opts="$opts -t ${SQLTAP_THREADS}"
opts="$opts --mysql-host ${MYSQL_HOST}"
opts="$opts --mysql-port ${MYSQL_PORT}"
opts="$opts --mysql-user ${MYSQL_USER}"
if [[ "x${MYSQL_PASSWORD}" != "x" ]]; then
opts="$opts --mysql-password ${MYSQL_PASSWORD}"
fi
opts="$opts --mysql-database ${MYSQL_DATABASE}"
opts="$opts --mysql-numconns ${MYSQL_NUMCONNS}"
opts="$opts --mysql-queuelen ${MYSQL_QUEUELEN}"
opts="$opts --cache-backend ${CACHE_BACKEND}"
if [[ "${CACHE_BACKEND}" == "memcache" ]]; then
require_args MEMCACHE_HOST \
MEMCACHE_PORT \
MEMCACHE_QUEUELEN \
MEMCACHE_NUMCONNS
opts="$opts --memcache-host ${MEMCACHE_HOST}"
opts="$opts --memcache-port ${MEMCACHE_PORT}"
opts="$opts --memcache-queuelen ${MEMCACHE_QUEUELEN}"
opts="$opts --memcache-numconns ${MEMCACHE_NUMCONNS}"
fi
opts="$opts ${SQLTAP_OPTS}"
report_to_statsd() {
if [[ -z "$STATSD_HOST" ]] || [[ -z "$STATSD_PORT" ]]; then
return
fi
sleep 10 # give some time to start sqltap
while sleep 1; do
curl -s "http://localhost:${SQLTAP_HTTP_PORT}/stats" | \
sed -e 's/,/\n/g' | \
sed -e 's/^[^"]*"//g' -e 's/": *"/:/g' -e 's/".*$//g' -e 's/^/'$STATSD_PREFIX'./g' -e 's/\.[^:.]*$//' -e 's/$/|c/' > \
/dev/udp/${STATSD_HOST}/${STATSD_PORT}
done
}
report_to_statsd&
exec java \
-Djava.rmi.server.hostname="${RMI_BIND}" \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port="${JMX_PORT}" \
-Dcom.sun.management.jmxremote.ssl=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Xmx"${JAVA_XMX}" -XX:GCTimeRatio=99 -XX:+UseConcMarkSweepGC \
-jar "${SQLTAP_JARFILE}" \
$opts