aboutsummaryrefslogtreecommitdiffstats
path: root/docker/instance_init.sh
diff options
context:
space:
mode:
authoryangyan <yangyanyj@chinamobile.com>2019-03-25 15:01:42 +0800
committeryangyan <yangyanyj@chinamobile.com>2019-03-25 15:01:58 +0800
commit6ac6fa2ab9c44ce965f24435b2429421132bf5d1 (patch)
tree13727282f045d344946e1c5fb61a742fae13bdbf /docker/instance_init.sh
parent7b731ee2dce023f0a5fa922b0ce13d3f2493f18a (diff)
change the way of create database
Change-Id: Ib75b63ebea6f444e66b1c3d5f98e5dfed058f976 Issue-ID: VFC-1312 Signed-off-by: yangyan <yangyanyj@chinamobile.com>
Diffstat (limited to 'docker/instance_init.sh')
-rwxr-xr-xdocker/instance_init.sh64
1 files changed, 62 insertions, 2 deletions
diff --git a/docker/instance_init.sh b/docker/instance_init.sh
index cfc9b0d5..7226e16c 100755
--- a/docker/instance_init.sh
+++ b/docker/instance_init.sh
@@ -1,2 +1,62 @@
-#!/bin/bash
-echo "No service needs init."
+#/bin/bash
+######
+# by vfc-db test
+#####
+# echo "No service needs init."
+#MYSQL_USER=$1
+######
+pip install PyMySQL==0.9.3
+mkdir -p /service/vfc/nfvo/lcm/resources/bin/logs
+mkdir -p /var/log/onap/vfc/nslcm/
+
+if [ ! -f /service/vfc/nfvo/lcm/resources/bin/logs/django.log ]; then
+ touch /service/vfc/nfvo/lcm/resources/bin/logs/django.log
+else
+ echo >/service/vfc/nfvo/lcm/resources/bin/logs/django.log
+fi
+if [ ! -f /var/log/onap/vfc/nslcm/runtime_nslcm.log ]; then
+ touch /var/log/onap/vfc/nslcm/runtime_nslcm.log
+else
+ echo >/var/log/onap/vfc/nslcm/runtime_nslcm.log
+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/db/resources/nslcm/bin
+ cd /service/vfc/nfvo/lcm/resources/bin
+ bash initDB.sh $MYSQL_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
+ man_path=/service/vfc/nfvo/lcm
+ 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='vfcnfvolcm';"`
+ tab1=`echo $tab |awk '{print $2}'`
+ echo "=========="
+ echo $tab1
+ echo "=========="
+ if [ $tab1 -eq 0 ] ; then
+ echo "============"
+ echo $tab1
+ echo "============"
+ echo "TABLE NOT EXISTS, START MIGRATE"
+ python $man_path/manage.py makemigrations && python $man_path/manage.py migrate &
+ 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='vfcnfvolcm';"`
+ tab3=`echo $tab2|awk '{print $2}'`
+ if [ $tab3 -gt 0 ] ; then
+ echo "TABLE CREATE uUCCESSFUL"
+ fi
+else
+ echo "table already existed"
+ exit 1
+fi
+ }
+
+if [ ! -f /service/vfc/nfvo/lcm/docker/db.txt ]; then
+ echo 1 > /service/vfc/nfvo/lcm/docker/db.txt
+ echo `pwd` >> db.txt
+ create_database
+else
+ echo "database already existed"
+fi