This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mariadb-installation-init.sh
executable file
·100 lines (65 loc) · 2.46 KB
/
mariadb-installation-init.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
#!/bin/bash
function sysexit {
echo $1
exit 1
}
# Test if any data exists - exit if any
# trace is found.
if [ -d "/var/lib/mysql/test" ] ; then
sysexit "ERROR: MariaDB data exist!"
fi
if [ -d "/var/lib/mysql/performance_schema" ] ; then
sysexit "ERROR: MariaDB data exist!"
fi
echo "Initializing MariaDB node. Please wait."
echo "Now installing MariaDB databases ... "
/usr/bin/mysql_install_db
echo "... done"
echo "Starting MariaDB Server ... "
(/usr/sbin/mysqld --wsrep_on=off &) || sysexit "ERROR: Could not bootstrap MariaDB server"
sleep 15
echo " ... done"
echo "Securing installation ..."
if [ ! -f /var/lib/mysql-shared/mysql_root_pass ] ; then
echo "Picking password ..."
# Pick a strong password, and remove trailing " -" generated by sha1sum
PASS=`head -n 300000 /dev/urandom | sha1sum - | sed 's/-//' | sed 's/ //' | tr -d "\t\n\r"`
echo -n $PASS > /var/lib/mysql-shared/mysql_root_pass || sysexit "Could not save password"
chown mysql:mysql /var/lib/mysql-shared/mysql_root_pass || sysexit "Could not save password"
chmod og-rwx /var/lib/mysql-shared/mysql_root_pass || sysexit "Could not save password"
echo "... password picked and saved."
else
PASS=`cat /var/lib/mysql-shared/mysql_root_pass`;
fi
PASS=`echo $PASS | sed 's/-//' | sed 's/ //' | tr -d "\t\n\r"`
(echo -e "\ny\n$PASS\n$PASS\ny\ny\ny\ny" | /usr/bin/mysql_secure_installation) || sysexit "Could not secure installation"
# Other nodes need to be able to access the cluster.
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'172%' IDENTIFIED BY \"$PASS\" WITH GRANT OPTION" | mysql -u root -p$PASS
echo "... done"
echo "Asking MariaDB to shut down, please wait ..."
# Stop mysqld
killall mysqld
# Wait for mysqld to shut down gracefully (else it will exit uncleanly).
while [ 1 ] ; do
MYSQLD_PROCESS=`ps -A|grep mysqld`;
if [ "$MYSQLD_PROCESS" == "" ] ; then
break
fi
echo -n "."
sleep 1
done
echo " MariaDB shut down."
#
# Add a MariaDB configuration file
# for SST transfer authentication -
# if you are wondering how this file
# is used, see the Dockerfile.
#
if [ ! -f /var/lib/mysql-shared/server-99-sst-auth.cnf ] ; then
echo "[galera]" > /var/lib/mysql-shared/server-99-sst-auth.cnf
echo "wsrep_sst_auth = root:$PASS" >> /var/lib/mysql-shared/server-99-sst-auth.cnf
chmod og-rwx /var/lib/mysql-shared/server-99-sst-auth.cnf
chown mysql:mysql /var/lib/mysql-shared/server-99-sst-auth.cnf
fi
echo "Everything is ready. Node is initialized and ready to use."
sync