summaryrefslogtreecommitdiffstats
path: root/compass-db/entrypoint.sh
blob: e01d29cd254e7ba8f5192a04d86dbc6d26b0fa5d (plain)
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
#!/bin/bash
set -x

create_users_and_dbs() {
    /usr/bin/mysqld_safe > /dev/null 2>&1 &

    timeout=30
    # wait up to 30 secs...
    while ! /usr/bin/mysqladmin -u root status > /dev/null 2>&1
    do
        timeout=$(($timeout - 1))
        if [ $timeout -eq 0 ]; then
            echo -e "\nCould not connect to database server. Aborting..."
            exit 1
        fi
        echo -n "."
        sleep 1
    done

    echo "Creating user..."
    mysqladmin -h127.0.0.1 --port=3306 -u root password root
    mysql -h127.0.0.1 --port=3306 -uroot -proot -e "create database compass"
    mysql -h127.0.0.1 --port=3306 -uroot -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root'"
    mysqladmin -uroot -proot shutdown
}

listen_on_all_interfaces() {
    cat > /etc/mysql/conf.d/mysql-listen.cnf <<EOF
[mysqld]
bind-address=0.0.0.0
[mysqld_safe]
bind-address=0.0.0.0
EOF
}


if [[ -z ${1} ]]; then
    create_users_and_dbs
    listen_on_all_interfaces
    /usr/bin/mysqld_safe
fi