f237235b6fc4815f3fcd4b5069004be3f83ee652
4 [ -z "$RO_DB_OVIM_HOST" ] && export RO_DB_OVIM_HOST
="$RO_DB_HOST"
5 [ -z "$RO_DB_OVIM_ROOT_PASSWORD" ] && export RO_DB_OVIM_ROOT_PASSWORD
="$RO_DB_ROOT_PASSWORD"
7 function is_db_created
() {
14 RESULT
=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" | grep -v Wildcard | grep -o $db_name`
15 if [ "$RESULT" == "$db_name" ]; then
17 RESULT
=`mysqlshow -h"$db_host" -P"$db_port" -u"$db_user" -p"$db_pswd" "$db_name" | grep -v Wildcard | grep schema_version`
18 #TODO validate version
19 if [ -n "$RESULT" ]; then
20 echo " DB $db_name exists and inited"
23 echo " DB $db_name exists BUT not inited"
27 echo " DB $db_name does not exist"
37 # Database ovim parameters
38 #db_ovim_host: localhost # by default localhost
39 #db_ovim_user: mano # DB user
40 #db_ovim_passwd: manopw # DB password
41 #db_ovim_name: mano_vim_db # Name of the OVIM MANO DB
44 sed -i "s/^db_host:.*/db_host: $RO_DB_HOST/" /etc
/osm
/openmanod.cfg ||
return 1
45 sed -i "s/^db_user:.*/db_user: $RO_DB_USER/" /etc
/osm
/openmanod.cfg ||
return 1
46 sed -i "s/^db_passwd:.*/db_passwd: $RO_DB_PASSWORD/" /etc
/osm
/openmanod.cfg ||
return 1
47 sed -i "s/^db_name:.*/db_name: $RO_DB_NAME/" /etc
/osm
/openmanod.cfg ||
return 1
48 sed -i "s/^db_ovim_host:.*/db_ovim_host: $RO_DB_OVIM_HOST/" /etc
/osm
/openmanod.cfg ||
return 1
49 sed -i "s/^db_ovim_user:.*/db_ovim_user: $RO_DB_OVIM_USER/" /etc
/osm
/openmanod.cfg ||
return 1
50 sed -i "s/^db_ovim_passwd:.*/db_ovim_passwd: $RO_DB_OVIM_PASSWORD/" /etc
/osm
/openmanod.cfg ||
return 1
51 sed -i "s/^db_ovim_name:.*/db_ovim_name: $RO_DB_OVIM_NAME/" /etc
/osm
/openmanod.cfg ||
return 1
60 echo "Wait until $max_attempts seconds for MySQL mano Server ${db_host}:${db_port} "
61 while ! mysqladmin
ping -h"$db_host" -P"$db_port" --silent; do
63 if [ $attempt -ge $max_attempts ]; then
65 echo "Can not connect to database ${db_host}:${db_port} during $max_attempts sec"
76 echo "1/4 Apply config"
80 echo "2/4 Wait for db up"
81 wait_db
"$RO_DB_HOST" "$RO_DB_PORT" ||
exit 1
82 [ "$RO_DB_OVIM_HOST" = "$RO_DB_HOST" ] || wait_db
"$RO_DB_OVIM_HOST" "$RO_DB_OVIM_PORT" ||
exit 1
85 echo "3/4 Init database"
86 RO_PATH
=`python -c 'import osm_ro; print(osm_ro.__path__[0])'`
87 echo "RO_PATH: $RO_PATH"
88 if ! is_db_created
"$RO_DB_HOST" "$RO_DB_PORT" "$RO_DB_USER" "$RO_DB_PASSWORD" "$RO_DB_NAME"
90 if [ -n "$RO_DB_ROOT_PASSWORD" ] ; then
91 mysqladmin
-h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" create
"$RO_DB_NAME"
92 echo "CREATE USER '${RO_DB_USER}'@'%' IDENTIFIED BY '${RO_DB_PASSWORD}';" |
93 mysql
-h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" ||
echo "user ${RO_DB_USER} already created?"
94 echo "GRANT ALL PRIVILEGES ON ${RO_DB_NAME}.* TO '${RO_DB_USER}'@'%';" |
95 mysql
-h"$RO_DB_HOST" -uroot -p"$RO_DB_ROOT_PASSWORD" ||
echo "user ${RO_DB_USER} already granted?"
97 ${RO_PATH}/database_utils
/init_mano_db.sh
-u "$RO_DB_USER" -p "$RO_DB_PASSWORD" -h "$RO_DB_HOST" \
98 -P "${RO_DB_PORT}" -d "${RO_DB_NAME}" ||
exit 1
100 echo " migrage database version"
101 ${RO_PATH}/database_utils
/migrate_mano_db.sh
-u "$RO_DB_USER" -p "$RO_DB_PASSWORD" -h "$RO_DB_HOST" \
102 -P "$RO_DB_PORT" -d "$RO_DB_NAME"
105 OVIM_PATH
=`python -c 'import lib_osm_openvim; print(lib_osm_openvim.__path__[0])'`
106 echo "OVIM_PATH: $OVIM_PATH"
107 if ! is_db_created
"$RO_DB_OVIM_HOST" "$RO_DB_OVIM_PORT" "$RO_DB_OVIM_USER" "$RO_DB_OVIM_PASSWORD" "$RO_DB_OVIM_NAME"
109 if [ -n "$RO_DB_OVIM_ROOT_PASSWORD" ] ; then
110 mysqladmin
-h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" create
"$RO_DB_OVIM_NAME"
111 echo "CREATE USER '${RO_DB_OVIM_USER}'@'%' IDENTIFIED BY '${RO_DB_OVIM_PASSWORD}';" |
112 mysql
-h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" ||
113 echo "user ${RO_DB_OVIM_USER} already created?"
114 echo "GRANT ALL PRIVILEGES ON ${RO_DB_OVIM_NAME}.* TO '${RO_DB_OVIM_USER}'@'%';" |
115 mysql
-h"$RO_DB_OVIM_HOST" -uroot -p"$RO_DB_OVIM_ROOT_PASSWORD" ||
116 echo "user ${RO_DB_OVIM_USER} already granted?"
118 ${OVIM_PATH}/database_utils
/init_vim_db.sh
-u "$RO_DB_OVIM_USER" -p "$RO_DB_OVIM_PASSWORD" -h "$RO_DB_OVIM_HOST" \
119 -P "${RO_DB_OVIM_PORT}" -d "${RO_DB_OVIM_NAME}" ||
exit 1
121 echo " migrage database version"
122 ${OVIM_PATH}/database_utils
/migrate_vim_db.sh
-u "$RO_DB_OVIM_USER" -p "$RO_DB_OVIM_PASSWORD" -h "$RO_DB_OVIM_HOST"\
123 -P "$RO_DB_OVIM_PORT" -d "$RO_DB_OVIM_NAME"
127 echo "4/4 Try to start"
128 # look for openmanod.cfg
129 RO_CONFIG_FILE
="/etc/osm/openmanod.cfg"
130 [ -f "$RO_CONFIG_FILE" ] || RO_CONFIG_FILE
=$
(python
-c 'import osm_ro; print(osm_ro.__path__[0])')/openmanod.cfg
131 [ -f "$RO_CONFIG_FILE" ] ||
! echo "configuration file 'openmanod.cfg' not found" ||
exit 1
133 openmanod
-c "$RO_CONFIG_FILE" --create-tenant=osm
# --log-file=/var/log/osm/openmano.log