-
Notifications
You must be signed in to change notification settings - Fork 1
/
startup.sh
70 lines (60 loc) · 2.32 KB
/
startup.sh
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
67
68
69
70
#!/bin/bash
export LANG=C.UTF-8
# Test connection to minio
while true; do
mc config host add vxm "$MINIO_ENDPOINT" "$MINIO_ACCESS_KEY" "$MINIO_SECRET_KEY" 2>&1 1>/dev/null
if [ $? -eq 0 ]; then
echo "connect to minio was successful"
break
fi
echo "failed to connect to minio"
sleep 1
done
mc mb --ignore-existing vxm/$MINIO_BUCKET_NAME
MODELS=$(jq -r '.[] | (.name + "/" + (.version.major|tostring) + "." + (.version.minor|tostring) + "." + (.version.patch|tostring))' config.json | uniq)
for dir in $MODELS; do
echo "remove module version $dir from global bucket"
mc rm --recursive --force vxm/$MINIO_BUCKET_NAME/${dir}
done
echo "remove utils from global bucket"
mc rm --recursive --force vxm/$MINIO_BUCKET_NAME/utils
echo "copy modules to global bucket"
mc cp --recursive /opt/vxmodules/mon/ vxm/$MINIO_BUCKET_NAME
# Test connection to mysql
while true; do
mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -e ";" 2>&1 1>/dev/null
if [ $? -eq 0 ]; then
echo "connect to mysql was successful"
break
fi
echo "failed to connect to mysql"
sleep 1
done
# Waiting migrations from vxapi into mysql
GET_MIGRATION="SELECT count(*) FROM gorp_migrations WHERE id = '0001_initial.sql';"
while true; do
MIGRATION=$(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" -Nse "$GET_MIGRATION" 2>/dev/null)
if [[ $? -eq 0 && $MIGRATION -eq 1 ]]; then
echo "vxapi migrations was found"
break
fi
echo "failed to update global modules table"
sleep 1
done
# update modules base columns into global DB
while true; do
mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" < /opt/vxmodules/dump_global.sql
echo "base updating of modules into global DB complete"
mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" < /opt/vxmodules/dump_global_sec_cfg.sql
echo "updating of modules secure config into global DB was complete"
GET_MODULES="SELECT name from modules;"
MODULES=$(mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" "$DB_NAME" -Nse "$GET_MODULES" 2>/dev/null)
echo "List of modules in database: $MODULES"
if [[ -n $MODULES ]]; then
echo "Modules uploaded to database"
break
fi
echo "failed to update global modules table"
sleep 1
done
sleep infinity