-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathstart-db.sh
executable file
·74 lines (60 loc) · 1.92 KB
/
start-db.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
#!/bin/bash
#
# script to set up container with mariadb in and initialize db for hotel
#
#
# to stop:
# $ docker stop sigmadb
#
# to remove
# $ docker rm -v sigmadb
#
usage() {
echo "Usage: $0 yml..."
}
PORT=4406 # use non-default port number on host
MONGO_PORT=4407
docker pull mariadb:10.4
if ! docker ps | grep -q sigmadb; then
echo "start db"
docker run --name sigmadb -e MYSQL_ROOT_PASSWORD=sigmadb -p $PORT:3306 -d mariadb
fi
until [ "`docker inspect -f {{.State.Running}} sigmadb`"=="true" ]; do
echo -n "." 1>&2
sleep 0.1;
done;
ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sigmadb)
echo "db IP: $ip"
until mariadb-show --skip-ssl -h $ip -u root -psigmadb 2> /dev/null; do
echo -n "." 1>&2
sleep 0.1;
done;
if ! mariadb-show --skip-ssl -h $ip -u root -psigmadb | grep -q sigmaos; then
echo "initialize db"
mariadb --skip-ssl -h $ip -u root -psigmadb <<ENDOFSQL
CREATE database sigmaos;
USE sigmaos;
source apps/hotel/init-db.sql;
CREATE USER 'sigma1'@'172.17.%.%' IDENTIFIED BY 'sigmaos1';
GRANT ALL PRIVILEGES ON sigmaos.* TO 'sigma1'@'172.17.%.%';
CREATE USER 'sigma1'@'192.168.%.%' IDENTIFIED BY 'sigmaos1';
GRANT ALL PRIVILEGES ON sigmaos.* TO 'sigma1'@'192.168.%.%';
CREATE USER 'sigma1'@'10.10.%.%' IDENTIFIED BY 'sigmaos1';
GRANT ALL PRIVILEGES ON sigmaos.* TO 'sigma1'@'10.10.%.%';
CREATE USER 'sigma1'@'10.0.%.%' IDENTIFIED BY 'sigmaos1';
GRANT ALL PRIVILEGES ON sigmaos.* TO 'sigma1'@'10.0.%.%';
FLUSH PRIVILEGES;
SET GLOBAL max_connections = 100000;
ENDOFSQL
fi
docker pull mongo:4.4.6
if ! docker ps | grep -q sigmamongo; then
echo "start mongodb"
docker run --name sigmamongo -p $MONGO_PORT:27017 -d mongo:4.4.6
fi
until [ "`docker inspect -f {{.State.Running}} sigmamongo`"=="true" ]; do
echo -n "." 1>&2
sleep 0.1;
done;
ip=$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' sigmamongo)
echo "mongo IP: $ip"