summaryrefslogtreecommitdiffstats
path: root/compass-db/entrypoint.sh
diff options
context:
space:
mode:
authorJustin chi <chigang@huawei.com>2017-11-03 08:43:45 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-11-03 08:43:45 +0000
commit936165548e0cd034ec118e43c1cc925ca2ac8b05 (patch)
treefe0b8740da4351c806da45afc6389e1c628c33cf /compass-db/entrypoint.sh
parentd143e4895b1674f35738b579eec0704bc50cd5fa (diff)
parent96edb4c56d964b73663c663b7b237e718ca3d4da (diff)
Merge "Add compass-db"
Diffstat (limited to 'compass-db/entrypoint.sh')
-rw-r--r--compass-db/entrypoint.sh41
1 files changed, 41 insertions, 0 deletions
diff --git a/compass-db/entrypoint.sh b/compass-db/entrypoint.sh
new file mode 100644
index 0000000..e01d29c
--- /dev/null
+++ b/compass-db/entrypoint.sh
@@ -0,0 +1,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