Implement simple onboarding cassandra upgrade
[sdc.git] / openecomp-be / dist / sdc-onboard-db-init-docker / artifacts / startup.sh
1 #!/bin/sh
2 SDC_HOME="/home/sdc"
3 cd $SDC_HOME || { echo "$(date) Failed to access directory $SDC_HOME"; exit 1; }
4
5 CS_PORT=""
6 CS_HOST=127.0.0.1
7
8 if [ -n "${CS_HOST_IP}" ]; then
9     CS_HOST=$CS_HOST_IP
10 fi
11
12 if [ -n "${CS_HOST_PORT}" ]; then
13     CS_PORT=$CS_HOST_PORT
14 fi
15
16 echo "$(date) [Info] Going to initialize sdc onboard cassandra: user=$SDC_USER; host=$CS_HOST; port=$CS_PORT"
17
18 echo "$(date) [Info] Initializing onboard keyspaces"
19 cqlsh -u "$SDC_USER" -p "$SDC_PASSWORD" -f init_keyspaces.cql "$CS_HOST" "$CS_PORT"
20 rc=$?
21
22 if [ $rc != 0 ]; then
23         echo "$(date) [Error] Failed to initialize onboard keyspaces";
24         exit $rc;
25 fi
26 echo "$(date) [Info] Finished initializing onboard keyspaces"
27
28 echo "$(date) [Info] Initializing onboard schemas"
29 cqlsh -u "$SDC_USER" -p "$SDC_PASSWORD" -f init_schemas.cql "$CS_HOST" "$CS_PORT"
30 rc=$?
31
32 if [ $rc != 0 ]; then
33         echo "$(date) [Error] Failed to initialize onboard schemas";
34         exit $rc;
35 fi
36 echo "$(date) [Info] Finished initializing onboard schemas"
37
38 echo "$(date) [Info] Upgrading onboard schemas"
39 for entry in "$SDC_HOME/upgrade-scripts"/*
40 do
41   echo "$(date) Running upgrade file '$entry'"
42   cqlsh -u "$SDC_USER" -p "$SDC_PASSWORD" -f "$entry" "$CS_HOST" "$CS_PORT"
43   rc=$?
44   if [ $rc != 0 ]; then
45     echo "$(date) [Warn] Upgrade failed for file '$entry'. It is possible that the upgrade was previously applied.";
46   fi
47   echo "$(date) Successfully ran upgrade file '$entry'"
48 done
49
50 echo "$(date) [Info] Onboarding init was successful"