forked from sttts/docker-galera-mariadb-10.0
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstart
executable file
·102 lines (86 loc) · 2.83 KB
/
start
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
#!/bin/bash -ex
if [ -z "$XTRABACKUP_PASSWORD" ]; then
echo "XTRABACKUP_PASSWORD not set"
exit 1
fi
CLUSTERCHECK_PASSWORD=$(echo "$XTRABACKUP_PASSWORD" | sha256sum | awk '{print $1;}')
QCOMM=""
CLUSTER_NAME=${CLUSTER_NAME:-cluster}
MYSQL_MODE_ARGS=""
NODE_ADDRESS=$(ip addr | awk '/inet/ && /ethwe/{sub(/\/.*$/,"",$2); print $2}')
case "$1" in
seed)
# bootstrapping
if [ ! -f /var/lib/mysql/skip-cluster-bootstrapping ]; then
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
MYSQL_ROOT_PASSWORD=$(openssl rand -base64 32)
echo "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD"
fi
cat >/tmp/bootstrap.sql <<EOF
CREATE USER 'xtrabackup'@'localhost' IDENTIFIED BY '$XTRABACKUP_PASSWORD';
GRANT RELOAD,LOCK TABLES,REPLICATION CLIENT ON *.* TO 'xtrabackup'@'localhost';
CREATE USER 'clustercheck'@'localhost' IDENTIFIED BY '$CLUSTERCHECK_PASSWORD';
GRANT PROCESS ON *.* TO 'clustercheck'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';
UPDATE mysql.user SET Password=PASSWORD('$MYSQL_ROOT_PASSWORD') WHERE User='root';
EOF
if [ "$MYSQL_DATABASE" ]; then
echo "CREATE DATABASE IF NOT EXISTS \`$MYSQL_DATABASE\` ;" >> /tmp/bootstrap.sql
fi
if [ "$MYSQL_USER" -a "$MYSQL_PASSWORD" ]; then
echo "CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;" >> /tmp/bootstrap.sql
if [ "$MYSQL_DATABASE" ]; then
echo "GRANT ALL ON \`$MYSQL_DATABASE\`.* TO '$MYSQL_USER'@'%' ;" >> /tmp/bootstrap.sql
fi
fi
echo "FLUSH PRIVILEGES;" >> /tmp/bootstrap.sql
MYSQL_MODE_ARGS+=" --init-file=/tmp/bootstrap.sql"
touch /var/lib/mysql/skip-cluster-bootstrapping
echo -n "Bootstrapping cluster. "
fi
MYSQL_MODE_ARGS+=" --wsrep-new-cluster"
shift 1
echo "Starting seed node"
;;
node)
if [ -z "$2" ]; then
echo "Missing master node address"
exit 1
fi
ADDRS="$2"
SEP=""
for ADDR in ${ADDRS//,/ }; do
if expr "$ADDR" : '^[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*$' >/dev/null; then
QCOMM+="$SEP$ADDR"
else
QCOMM+="$SEP$(host -t A "$ADDR" | awk '{ print $4 }' | paste -sd ",")"
fi
SEP=,
done
shift 2
echo "Starting node, connecting to qcomm://$QCOMM"
;;
*)
echo "seed|node <othernode>,..."
exit 1
esac
# start processes
set +e -m
function shutdown () {
echo Shutting down
test -s /var/run/mysql/mysqld.pid && kill -TERM $(cat /var/run/mysql/mysqld.pid)
}
trap shutdown TERM INT
/bin/galera-healthcheck -password="$CLUSTERCHECK_PASSWORD" -pidfile=/var/run/galera-healthcheck.pid -user clustercheck &
/mysqld.sh --console \
$MYSQL_MODE_ARGS \
--wsrep_cluster_name="$CLUSTER_NAME" \
--wsrep_cluster_address="gcomm://$QCOMM" \
--wsrep_node_address="$NODE_ADDRESS:4567" \
--wsrep_sst_auth="xtrabackup:$XTRABACKUP_PASSWORD" \
--default-time-zone="+00:00" \
"$@" 2>&1 &
wait $!
RC=$?
test -s /var/run/galera-healthcheck.pid && kill $(cat /var/run/galera-healthcheck.pid)
exit $RC