aboutsummaryrefslogtreecommitdiffstats
path: root/docker/instance_init.sh
blob: 6e51cc1706617715ba8284a07a8c3aa9e0c39d64 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/bash
######
# by vfc-db test
#####
# echo "No service needs init."
#MYSQL_USER=$1
######
#by duan
pip install PyMySQL==0.9.3
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

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
else
    echo >/service/vfc/nfvo/catalog/resources/bin/logs/runtime_catalog.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/catalog/resources/bin
    bash initDB.sh $MYSQL_USER $MYSQL_ROOT_PASSWORD $MYSQL_PORT $MYSQL_IP
    #DIRNAME=`dirname $0`
    #HOME=`cd $DIRNAME/; pwd`
    #man_path=$HOME/../
    man_path=/service/vfc/nfvo/catalog
    #tab=`mysql -u${MYSQL_USER} -p${MYSQL_PASSWORD} -P${MYSQL_PORT} -h${MYSQL_IP} -e "use vfcnfvolcm; select count(*) from vfcnfvolcm;"`
    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}'`
	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 database && 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='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
    echo `pwd` >> /service/vfc/nfvo/catalog/docker/db.txt
    create_database
else
    echo "database already existed"
fi