aboutsummaryrefslogtreecommitdiffstats
path: root/docker/instance_init.sh
diff options
context:
space:
mode:
authoryangyan <yangyanyj@chinamobile.com>2019-04-02 17:44:22 +0800
committeryangyan <yangyanyj@chinamobile.com>2019-04-02 17:44:29 +0800
commitcc20b0c0b4d57bc2add992e28f7249ae99cf4785 (patch)
treec85314daad65bfccda2c0f06db1a355d49fc7e57 /docker/instance_init.sh
parent5d77874acf20b5520863721f408f04f03d001a84 (diff)
Fix docker init and config file
Change-Id: I75cf8fd885531221d437c71af0f2dad3dc3dd2ba Issue-ID: VFC-1332 Signed-off-by: yangyan <yangyanyj@chinamobile.com>
Diffstat (limited to 'docker/instance_init.sh')
-rwxr-xr-xdocker/instance_init.sh56
1 files changed, 18 insertions, 38 deletions
diff --git a/docker/instance_init.sh b/docker/instance_init.sh
index 64b8e864..d6ddbf60 100755
--- a/docker/instance_init.sh
+++ b/docker/instance_init.sh
@@ -1,51 +1,31 @@
#!/bin/bash
-if [ ! -f /var/log/onap/vfc/catalog/runtime_catalog.log ]; then
- mkdir -p /var/log/onap/vfc/catalog
- touch /var/log/onap/vfc/catalog/runtime_catalog.log
-else
- echo >/var/log/onap/vfc/catalog/runtime_catalog.log
-fi
+MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
+MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
-if [ ! -f /service/vfc/nfvo/catalog/resources/bin/logs/runtime_catalog.log ]; then
- mkdir -p /service/vfc/nfvo/catalog/resources/bin/logs
- touch /service/vfc/nfvo/catalog/resources/bin/logs/runtime_catalog.log
+if [ $MYSQL_AUTH ]; then
+ MYSQL_ROOT_USER=`echo $MYSQL_AUTH | cut -d: -f 1`
+ MYSQL_ROOT_PASSWORD=`echo $MYSQL_AUTH | cut -d: -f 2`
else
- echo >/service/vfc/nfvo/catalog/resources/bin/logs/runtime_catalog.log
+ MYSQL_ROOT_USER="root"
+ MYSQL_ROOT_PASSWORD="root"
fi
-MYSQL_IP=`echo $MYSQL_ADDR | cut -d: -f 1`
-MYSQL_PORT=`echo $MYSQL_ADDR | cut -d: -f 2`
-MYSQL_USER=`echo $MYSQL_AUTH | cut -d: -f 1`
-MYSQL_ROOT_PASSWORD=`echo $MYSQL_AUTH | cut -d: -f 2`
-
function create_database {
cd /service/vfc/nfvo/catalog/resources/bin
- bash initDB.sh $MYSQL_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
-
- man_path=/service/vfc/nfvo/catalog
-
- tab=`mysql -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} -P${MYSQL_PORT} -h${MYSQL_IP} -e "SELECT count(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA='nfvocatalog';"`
- tab1=`echo $tab |awk '{print $2}'`
+ bash initDB.sh $MYSQL_ROOT_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
- echo "TABLE NOT EXISTS, START MIGRATE"
- python $man_path/manage.py makemigrations database && python $man_path/manage.py migrate database &
- wait
- tab2=`mysql -u${MYSQL_USER} -p${MYSQL_ROOT_PASSWORD} -P${MYSQL_PORT} -h${MYSQL_IP} -e "SELECT count(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA='nfvocatalog';"`
- tab3=`echo $tab2|awk '{print $2}'`
- if [ $tab3 -gt 0 ] ; then
- echo "TABLE CREATE SUCCESSFUL"
- fi
-else
- echo "table already existed"
- exit 1
-fi
}
-if [ ! -f /service/vfc/nfvo/catalog/docker/db.txt ]; then
- echo 1 > /service/vfc/nfvo/catalog/docker/db.txt
-
+function migrate_database {
+ cd /service/vfc/nfvo/catalog
+ python manage.py makemigrations database
+ python manage.py migrate
+}
+
+cd /service
+if [ ! -f dbexist.txt ]; then
+ echo 1 > dbexist.txt
create_database
-else
- echo "database already existed"
+ migrate_database
fi