-
Notifications
You must be signed in to change notification settings - Fork 0
/
shell-entrypoint.sh
executable file
·62 lines (50 loc) · 2.13 KB
/
shell-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
#!/bin/sh
SLEEP_TIME=4
MAX_TIME=60
set -e
echo "Started."
echo "MYSQL_USER: ${MYSQL_USER}"
echo "MYSQL_PASSWORD: ${MYSQL_PASSWORD}"
echo "MYSQL_PORT: ${MYSQL_PORT}"
echo "MYSQL_CLUSTER_NAME: ${MYSQL_CLUSTER_NAME}"
echo "MYSQL_CLUSTER_OPTIONS: ${MYSQL_CLUSTER_OPTIONS}"
cat > /tmp/create-cluster.js <<EOF
const mysqlUser = '${MYSQL_USER}';
const mysqlPassword = '${MYSQL_PASSWORD}';
const mysqlPort = '${MYSQL_PORT}';
const clusterName = '${MYSQL_CLUSTER_NAME}';
const clusterOptions = ${MYSQL_CLUSTER_OPTIONS};
dba.checkInstanceConfiguration({user: mysqlUser, password: mysqlPassword, host: 'server-1', port: mysqlPort});
dba.configureInstance({user: mysqlUser, password: mysqlPassword, host: 'server-1', port: mysqlPort},{clearReadOnly: true, interactive: false});
const cluster = dba.createCluster(clusterName, clusterOptions);
dba.checkInstanceConfiguration({user: mysqlUser, password: mysqlPassword, host: 'server-2', port: mysqlPort});
dba.configureInstance({user: mysqlUser, password: mysqlPassword, host: 'server-2', port: mysqlPort},{clearReadOnly: true, interactive: false});
cluster.addInstance({user: mysqlUser, password: mysqlPassword, host: 'server-2'}, {recoveryMethod: 'clone', interactive:false});
dba.checkInstanceConfiguration({user: mysqlUser, password: mysqlPassword, host: 'server-3', port: mysqlPort});
dba.configureInstance({user: mysqlUser, password: mysqlPassword, host: 'server-3', port: mysqlPort},{clearReadOnly: true, interactive: false});
cluster.addInstance({user: mysqlUser, password: mysqlPassword, host: 'server-3'}, {recoveryMethod: 'clone', interactive:false});
EOF
echo "Attempting to create cluster."
until ( \
mysqlsh \
--user=${MYSQL_USER} \
--password=${MYSQL_PASSWORD} \
--host=server-1 \
--port=${MYSQL_PORT} \
--interactive \
--schema="mysql" \
--file=/tmp/create-cluster.js \
)
do
echo "Cluster creation failed."
if [ $SECONDS -gt $MAX_TIME ]
then
echo "Maximum time of $MAX_TIME exceeded."
echo "Exiting."
exit 1
fi
echo "Sleeping for $SLEEP_TIME seconds."
sleep $SLEEP_TIME
done
echo "Cluster created."
echo "Exiting."