summaryrefslogtreecommitdiff
path: root/devobsserver/script/initdb.sh
diff options
context:
space:
mode:
Diffstat (limited to 'devobsserver/script/initdb.sh')
-rwxr-xr-xdevobsserver/script/initdb.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/devobsserver/script/initdb.sh b/devobsserver/script/initdb.sh
new file mode 100755
index 0000000..1ec2e5d
--- /dev/null
+++ b/devobsserver/script/initdb.sh
@@ -0,0 +1,54 @@
+#!/bin/bash
+#===============================================================================
+# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd.
+# Author onstudy@samsung.com
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+# See the GNU General Public License for more details.
+#===============================================================================
+set -e
+
+echo "initdb.sh start"
+
+if [[ ! -d $MYSQL_DATA_DIR_DEFAULT/$MYSQL_API_DATABASE ]]; then
+ if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
+ echo >&2 'error: database is uninitialized and MYSQL_ROOT_PASSWORD not set'
+ echo >&2 ' Did you forget to add -e MYSQL_ROOT_PASSWORD=... ?'
+ exit 1
+ fi
+
+ /usr/sbin/rcmysql start
+ # Allow some time for the service to start
+ sleep 5
+
+ echo "create database start"
+
+ echo "change root password"
+ mysql -u root <<-EOFMYSQL
+ DELETE FROM mysql.user ;
+ CREATE USER 'root'@'%' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}' ;
+ GRANT ALL ON *.* TO 'root'@'%' WITH GRANT OPTION ;
+ DROP DATABASE IF EXISTS test ;
+ CREATE DATABASE IF NOT EXISTS $MYSQL_API_DATABASE ;
+ CREATE DATABASE IF NOT EXISTS $MYSQL_WEBUI_DATABASE ;
+ CREATE USER '$MYSQL_USER'@'%' IDENTIFIED BY '$MYSQL_PASSWORD' ;
+ CREATE USER '$MYSQL_USER'@'localhost' IDENTIFIED BY '$MYSQL_PASSWORD' ;
+ GRANT ALL ON $MYSQL_API_DATABASE.* TO '$MYSQL_USER'@'%','$MYSQL_USER'@'localhost' ;
+ GRANT ALL ON $MYSQL_WEBUI_DATABASE.* TO '$MYSQL_USER'@'%','$MYSQL_USER'@'localhost' ;
+ FLUSH PRIVILEGES ;
+ EOFMYSQL
+ echo "create database end"
+ /usr/sbin/rcmysql stop
+ # Allow some time for the service to start
+ sleep 5
+fi
+
+chown -R mysql:mysql /var/lib/mysql
+
+echo "initdb.sh end"