blob: 65811f6fc6cc19ce109961684957b26d3c9f9224 [file] [log] [blame]
sebdetdf353be2020-09-21 22:13:05 +02001#!/bin/sh
andre.schmidb8bfef32021-08-12 23:05:15 +01002SDC_HOME="/home/sdc"
3cd $SDC_HOME || { echo "$(date) Failed to access directory $SDC_HOME"; exit 1; }
Avi Zivc175a0d2018-03-15 13:21:44 +02004
5CS_PORT=""
6CS_HOST=127.0.0.1
7
andre.schmidb8bfef32021-08-12 23:05:15 +01008if [ -n "${CS_HOST_IP}" ]; then
Avi Zivc175a0d2018-03-15 13:21:44 +02009 CS_HOST=$CS_HOST_IP
10fi
11
andre.schmidb8bfef32021-08-12 23:05:15 +010012if [ -n "${CS_HOST_PORT}" ]; then
Avi Zivc175a0d2018-03-15 13:21:44 +020013 CS_PORT=$CS_HOST_PORT
14fi
15
andre.schmidb8bfef32021-08-12 23:05:15 +010016echo "$(date) [Info] Going to initialize sdc onboard cassandra: user=$SDC_USER; host=$CS_HOST; port=$CS_PORT"
Avi Zivc175a0d2018-03-15 13:21:44 +020017
andre.schmidb8bfef32021-08-12 23:05:15 +010018echo "$(date) [Info] Initializing onboard keyspaces"
MichaelMorris0ba58882021-09-06 20:36:02 +010019cqlsh -u $SDC_USER -p $SDC_PASSWORD -f init_keyspaces.cql $CS_HOST $CS_PORT
k.kedron57844f32019-07-09 15:44:54 +020020rc=$?
Avi Zivc175a0d2018-03-15 13:21:44 +020021
sebdetdf353be2020-09-21 22:13:05 +020022if [ $rc != 0 ]; then
andre.schmidb8bfef32021-08-12 23:05:15 +010023 echo "$(date) [Error] Failed to initialize onboard keyspaces";
k.kedron57844f32019-07-09 15:44:54 +020024 exit $rc;
Ofir Sonsinof4dcec32019-06-23 16:20:50 +030025fi
andre.schmidb8bfef32021-08-12 23:05:15 +010026echo "$(date) [Info] Finished initializing onboard keyspaces"
Ofir Sonsinof4dcec32019-06-23 16:20:50 +030027
andre.schmidb8bfef32021-08-12 23:05:15 +010028echo "$(date) [Info] Initializing onboard schemas"
MichaelMorris0ba58882021-09-06 20:36:02 +010029cqlsh -u $SDC_USER -p $SDC_PASSWORD -f init_schemas.cql $CS_HOST $CS_PORT
k.kedron57844f32019-07-09 15:44:54 +020030rc=$?
Ofir Sonsinof4dcec32019-06-23 16:20:50 +030031
sebdetdf353be2020-09-21 22:13:05 +020032if [ $rc != 0 ]; then
andre.schmidb8bfef32021-08-12 23:05:15 +010033 echo "$(date) [Error] Failed to initialize onboard schemas";
k.kedron57844f32019-07-09 15:44:54 +020034 exit $rc;
35fi
andre.schmidb8bfef32021-08-12 23:05:15 +010036echo "$(date) [Info] Finished initializing onboard schemas"
37
38echo "$(date) [Info] Upgrading onboard schemas"
39for entry in "$SDC_HOME/upgrade-scripts"/*
40do
41 echo "$(date) Running upgrade file '$entry'"
MichaelMorris0ba58882021-09-06 20:36:02 +010042 cqlsh -u $SDC_USER -p $SDC_PASSWORD -f $entry $CS_HOST $CS_PORT
andre.schmidb8bfef32021-08-12 23:05:15 +010043 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'"
48done
49
MichaelMorris0ba58882021-09-06 20:36:02 +010050echo "$(date) [Info] Onboarding init was successful"