blob: 891c8915f37559e94c1e257f069e3888d979712c [file] [log] [blame]
Instrumentalbc299c02018-09-25 06:42:31 -05001#!/bin/bash
2#
3# Engage normal Cass Init, then check for data installation
4#
Instrumental08e93402018-10-03 08:38:52 -05005DIR="/opt/app/aaf/status"
Instrumentale66f4282018-10-16 14:09:31 -05006INSTALLED_VERSION=/opt/app/aaf/cass_init/INSTALLED_VERSION
Instrumental08e93402018-10-03 08:38:52 -05007
Instrumentalbc299c02018-09-25 06:42:31 -05008if [ ! -e /aaf_cmd ]; then
9 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
10 chmod u+x /aaf_cmd
11fi
12
Instrumentalf0ddaf22018-10-03 22:29:23 -050013# Always need startup status...
14if [ ! -e "$DIR" ]; then
15 mkdir -p "$DIR"
16fi
17
Instrumental08e93402018-10-03 08:38:52 -050018function status {
Instrumental08e93402018-10-03 08:38:52 -050019 echo "$@"
20 echo "$@" > $DIR/aaf_cass
Instrumental08e93402018-10-03 08:38:52 -050021}
22
Instrumental1e3be602018-10-03 19:40:44 -050023function wait_start {
Instrumental08e93402018-10-03 08:38:52 -050024 sleep 10
25 status wait for cassandra to start
Instrumental1e3be602018-10-03 19:40:44 -050026 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
27 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
28 echo "Waiting for Cassandra to start... Sleep 10"
29 sleep 10
30 else
31 break
32 fi
33 done
34}
35
Instrumentalf0ddaf22018-10-03 22:29:23 -050036
Instrumental1e3be602018-10-03 19:40:44 -050037function wait_cql {
38 status wait for keyspace to be initialized
39 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
Instrumental235dd9a2018-10-03 21:36:44 -050040 if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
Instrumental1e3be602018-10-03 19:40:44 -050041 break
42 else
43 echo "Waiting for Keyspaces to be loaded... Sleep 10"
44 sleep 10
45 fi
46 done
47}
48
Instrumentalf0ddaf22018-10-03 22:29:23 -050049function wait_ready {
50 status wait for cassandra to be fully ready
51 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
52 STATUS="$(cat $DIR/aaf_cass)"
53 if [ "$STATUS" = "ready" ]; then
54 break
55 else
56 echo "Waiting for Start, $STATUS... Sleep 10"
57 sleep 10
58 fi
59 done
60}
61
Instrumental1e3be602018-10-03 19:40:44 -050062function install_cql {
63 wait_start started
Instrumentalbc299c02018-09-25 06:42:31 -050064 # Now, make sure data exists
Instrumentale66f4282018-10-16 14:09:31 -050065 if [ ! -e $INSTALLED_VERSION ] && [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
66 /usr/bin/cqlsh -e 'DROP KEYSPACE authz'
67 fi
68 if [ -z "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" ]; then
69 status install
70 echo "Initializing Cassandra DB"
Instrumentalbc299c02018-09-25 06:42:31 -050071 echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following "
72 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
73 echo ""
74 echo " cd /opt/app/aaf/cass_init"
75 cd /opt/app/aaf/cass_init
76 echo " cqlsh -f keyspace.cql"
77 /usr/bin/cqlsh -f keyspace.cql
Instrumental08e93402018-10-03 08:38:52 -050078 status keyspace installed
Instrumentalbc299c02018-09-25 06:42:31 -050079 echo " cqlsh -f init.cql"
80 /usr/bin/cqlsh -f init.cql
Instrumental08e93402018-10-03 08:38:52 -050081 status data initialized
Instrumentalbc299c02018-09-25 06:42:31 -050082 echo ""
83 echo "The following will give you a temporary identity with which to start working, or emergency"
84 echo " cqlsh -f temp_identity.cql"
Instrumentale66f4282018-10-16 14:09:31 -050085 echo "2.1.15"> $INSTALLED_VERSION
86 else
87 echo "Cassandra DB already includes 'authz' keyspace"
Instrumentalbc299c02018-09-25 06:42:31 -050088 fi
Instrumental08e93402018-10-03 08:38:52 -050089 status $1
Instrumentalbc299c02018-09-25 06:42:31 -050090}
91
Instrumental08e93402018-10-03 08:38:52 -050092function install_onap {
Instrumentala9391132018-10-16 12:34:12 -050093 echo " cd /opt/app/aaf/cass_init"
Instrumental94053612018-10-08 11:27:18 -050094 install_cql initialized
95 status prep data for bootstrapping
Instrumentale66f4282018-10-16 14:09:31 -050096 cd /opt/app/aaf/cass_init
Instrumental94053612018-10-08 11:27:18 -050097 bash prep.sh
98 status push data to cassandra
99 bash push.sh
Instrumentala9391132018-10-16 12:34:12 -0500100 cd -
Instrumental08e93402018-10-03 08:38:52 -0500101 status ready
102}
103
104case "$1" in
105 start)
106 # start install_cql in background, waiting for process to start
107 install_cql ready &
108
109 # Startup like normal
110 echo "Cassandra Startup"
111 /usr/local/bin/docker-entrypoint.sh
112 ;;
Instrumental1e3be602018-10-03 19:40:44 -0500113 wait)
114 # Wait for initialization. This can be called from Docker only as a check to make sure it is ready
Instrumentalf0ddaf22018-10-03 22:29:23 -0500115 wait_ready
Instrumental1e3be602018-10-03 19:40:44 -0500116
Instrumental1e3be602018-10-03 19:40:44 -0500117 ;;
Instrumental08e93402018-10-03 08:38:52 -0500118 onap)
Instrumentale66f4282018-10-16 14:09:31 -0500119 cd /opt/app/aaf/cass_init
Instrumental08e93402018-10-03 08:38:52 -0500120 # start install_onap (which calls install_cql first) in background, waiting for process to start
121 install_onap &
122
123 # Startup like normal
124 echo "Cassandra Startup"
125 /usr/local/bin/docker-entrypoint.sh
Instrumentalbc299c02018-09-25 06:42:31 -0500126 ;;
127esac
128