blob: ec8cf6b7dbcbe0419d3b688eb731c12d88f1f900 [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"
6
Instrumentalbc299c02018-09-25 06:42:31 -05007if [ ! -e /aaf_cmd ]; then
8 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
9 chmod u+x /aaf_cmd
10fi
11
Instrumentalf0ddaf22018-10-03 22:29:23 -050012# Always need startup status...
13if [ ! -e "$DIR" ]; then
14 mkdir -p "$DIR"
15fi
16
Instrumental08e93402018-10-03 08:38:52 -050017function status {
Instrumental08e93402018-10-03 08:38:52 -050018 echo "$@"
19 echo "$@" > $DIR/aaf_cass
Instrumental08e93402018-10-03 08:38:52 -050020}
21
Instrumental1e3be602018-10-03 19:40:44 -050022function wait_start {
Instrumental08e93402018-10-03 08:38:52 -050023 sleep 10
24 status wait for cassandra to start
Instrumental1e3be602018-10-03 19:40:44 -050025 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
26 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
27 echo "Waiting for Cassandra to start... Sleep 10"
28 sleep 10
29 else
30 break
31 fi
32 done
33}
34
Instrumentalf0ddaf22018-10-03 22:29:23 -050035
Instrumental1e3be602018-10-03 19:40:44 -050036function wait_cql {
37 status wait for keyspace to be initialized
38 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 -050039 if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
Instrumental1e3be602018-10-03 19:40:44 -050040 break
41 else
42 echo "Waiting for Keyspaces to be loaded... Sleep 10"
43 sleep 10
44 fi
45 done
46}
47
Instrumentalf0ddaf22018-10-03 22:29:23 -050048function wait_ready {
49 status wait for cassandra to be fully ready
50 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
51 STATUS="$(cat $DIR/aaf_cass)"
52 if [ "$STATUS" = "ready" ]; then
53 break
54 else
55 echo "Waiting for Start, $STATUS... Sleep 10"
56 sleep 10
57 fi
58 done
59}
60
Instrumental1e3be602018-10-03 19:40:44 -050061function install_cql {
62 wait_start started
Instrumentalbc299c02018-09-25 06:42:31 -050063 # Now, make sure data exists
64 if [ "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" = "" ]; then
Instrumental1e3be602018-10-03 19:40:44 -050065 status install
Instrumentalbc299c02018-09-25 06:42:31 -050066 echo "Initializing Cassandra DB"
67 if [ "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" == "" ]; then
68 echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following "
69 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
70 echo ""
71 echo " cd /opt/app/aaf/cass_init"
72 cd /opt/app/aaf/cass_init
73 echo " cqlsh -f keyspace.cql"
74 /usr/bin/cqlsh -f keyspace.cql
Instrumental08e93402018-10-03 08:38:52 -050075 status keyspace installed
Instrumentalbc299c02018-09-25 06:42:31 -050076 echo " cqlsh -f init.cql"
77 /usr/bin/cqlsh -f init.cql
Instrumental08e93402018-10-03 08:38:52 -050078 status data initialized
Instrumentalbc299c02018-09-25 06:42:31 -050079 echo ""
80 echo "The following will give you a temporary identity with which to start working, or emergency"
81 echo " cqlsh -f temp_identity.cql"
82 fi
83 fi
Instrumental08e93402018-10-03 08:38:52 -050084 status $1
Instrumentalbc299c02018-09-25 06:42:31 -050085}
86
Instrumental08e93402018-10-03 08:38:52 -050087function install_onap {
Instrumentala9391132018-10-16 12:34:12 -050088 echo " cd /opt/app/aaf/cass_init"
89 cd /opt/app/aaf/cass_init
Instrumental94053612018-10-08 11:27:18 -050090 install_cql initialized
91 status prep data for bootstrapping
92 bash prep.sh
93 status push data to cassandra
94 bash push.sh
Instrumentala9391132018-10-16 12:34:12 -050095 cd -
Instrumental08e93402018-10-03 08:38:52 -050096 status ready
97}
98
99case "$1" in
100 start)
101 # start install_cql in background, waiting for process to start
102 install_cql ready &
103
104 # Startup like normal
105 echo "Cassandra Startup"
106 /usr/local/bin/docker-entrypoint.sh
107 ;;
Instrumental1e3be602018-10-03 19:40:44 -0500108 wait)
109 # 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 -0500110 wait_ready
Instrumental1e3be602018-10-03 19:40:44 -0500111
Instrumental1e3be602018-10-03 19:40:44 -0500112 ;;
Instrumental08e93402018-10-03 08:38:52 -0500113 onap)
114 # start install_onap (which calls install_cql first) in background, waiting for process to start
115 install_onap &
116
117 # Startup like normal
118 echo "Cassandra Startup"
119 /usr/local/bin/docker-entrypoint.sh
Instrumentalbc299c02018-09-25 06:42:31 -0500120 ;;
121esac
122