-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
56 lines (46 loc) · 1.19 KB
/
start.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
#!/bin/bash
#
# Copy/dervied from code held at https://github.com/Tommi2Day/mysql4
#
set -e
HOSTNAME=${HOSTNAME:-mysql4mirror}
MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD:-mysql4mirror}
# Only run if you are in a docker container. If we are in
# singularity we probably won't have the rights to write to /etc/hosts
# or it's a bad idea
if [ -f /.dockerenv ]; then
if ! grep $HOSTNAME /etc/hosts >/dev/null; then
echo "127.0.0.1 $HOSTNAME">> /etc/hosts
fi
fi
if [ "$1" = 'mysqld_safe' ]; then
# Again can only do if in Docker
if [ -f /.dockerenv ]; then
chown -R mysql:mysql /db
fi
if ! ls -1 /db/* 1>/dev/null 2>&1 ; then
echo "Initializing database..."
if [ -f /.dockerenv ]; then
mysql_install_db --user=mysql
else
mysql_install_db
fi
echo "Setting root password..."
mysqld_safe --skip-networking &
sleep 5
#enable full network acess
mysql --safe-updates -uroot mysql <<-EOS
SET @@SESSION.SQL_LOG_BIN=0;
DELETE FROM user where host in ('localhost','$HOSTNAME');
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';
FLUSH PRIVILEGES ;
EOS
sleep 5
kill $(cat /db/*.pid)
sleep 5
fi
fi
#run it
if [ -n "$@" ]; then
exec "$@"
fi