sebdet | df353be | 2020-09-21 22:13:05 +0200 | [diff] [blame] | 1 | #!/bin/sh |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 2 | SDC_HOME="/home/sdc" |
| 3 | cd $SDC_HOME || { echo "$(date) Failed to access directory $SDC_HOME"; exit 1; } |
Avi Ziv | c175a0d | 2018-03-15 13:21:44 +0200 | [diff] [blame] | 4 | |
| 5 | CS_PORT="" |
| 6 | CS_HOST=127.0.0.1 |
| 7 | |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 8 | if [ -n "${CS_HOST_IP}" ]; then |
Avi Ziv | c175a0d | 2018-03-15 13:21:44 +0200 | [diff] [blame] | 9 | CS_HOST=$CS_HOST_IP |
| 10 | fi |
| 11 | |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 12 | if [ -n "${CS_HOST_PORT}" ]; then |
Avi Ziv | c175a0d | 2018-03-15 13:21:44 +0200 | [diff] [blame] | 13 | CS_PORT=$CS_HOST_PORT |
| 14 | fi |
| 15 | |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 16 | echo "$(date) [Info] Going to initialize sdc onboard cassandra: user=$SDC_USER; host=$CS_HOST; port=$CS_PORT" |
Avi Ziv | c175a0d | 2018-03-15 13:21:44 +0200 | [diff] [blame] | 17 | |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 18 | echo "$(date) [Info] Initializing onboard keyspaces" |
MichaelMorris | 0ba5888 | 2021-09-06 20:36:02 +0100 | [diff] [blame] | 19 | cqlsh -u $SDC_USER -p $SDC_PASSWORD -f init_keyspaces.cql $CS_HOST $CS_PORT |
k.kedron | 57844f3 | 2019-07-09 15:44:54 +0200 | [diff] [blame] | 20 | rc=$? |
Avi Ziv | c175a0d | 2018-03-15 13:21:44 +0200 | [diff] [blame] | 21 | |
sebdet | df353be | 2020-09-21 22:13:05 +0200 | [diff] [blame] | 22 | if [ $rc != 0 ]; then |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 23 | echo "$(date) [Error] Failed to initialize onboard keyspaces"; |
k.kedron | 57844f3 | 2019-07-09 15:44:54 +0200 | [diff] [blame] | 24 | exit $rc; |
Ofir Sonsino | f4dcec3 | 2019-06-23 16:20:50 +0300 | [diff] [blame] | 25 | fi |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 26 | echo "$(date) [Info] Finished initializing onboard keyspaces" |
Ofir Sonsino | f4dcec3 | 2019-06-23 16:20:50 +0300 | [diff] [blame] | 27 | |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 28 | echo "$(date) [Info] Initializing onboard schemas" |
MichaelMorris | 0ba5888 | 2021-09-06 20:36:02 +0100 | [diff] [blame] | 29 | cqlsh -u $SDC_USER -p $SDC_PASSWORD -f init_schemas.cql $CS_HOST $CS_PORT |
k.kedron | 57844f3 | 2019-07-09 15:44:54 +0200 | [diff] [blame] | 30 | rc=$? |
Ofir Sonsino | f4dcec3 | 2019-06-23 16:20:50 +0300 | [diff] [blame] | 31 | |
sebdet | df353be | 2020-09-21 22:13:05 +0200 | [diff] [blame] | 32 | if [ $rc != 0 ]; then |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 33 | echo "$(date) [Error] Failed to initialize onboard schemas"; |
k.kedron | 57844f3 | 2019-07-09 15:44:54 +0200 | [diff] [blame] | 34 | exit $rc; |
| 35 | fi |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 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'" |
MichaelMorris | 0ba5888 | 2021-09-06 20:36:02 +0100 | [diff] [blame] | 42 | cqlsh -u $SDC_USER -p $SDC_PASSWORD -f $entry $CS_HOST $CS_PORT |
andre.schmid | b8bfef3 | 2021-08-12 23:05:15 +0100 | [diff] [blame] | 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 | |
MichaelMorris | 0ba5888 | 2021-09-06 20:36:02 +0100 | [diff] [blame] | 50 | echo "$(date) [Info] Onboarding init was successful" |