blob: 0683fde2d8af378fa12756424b29a8cea28aeb54 [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"
Instrumental50c23cc2018-10-31 02:40:03 -05006INSTALLED_VERSION=/var/lib/cassandra/AAF_VERSION
7AAF_INIT_DATA=/var/lib/cassandra/AAF_INIT_DATA
Instrumental08e93402018-10-03 08:38:52 -05008
Instrumentalbc299c02018-09-25 06:42:31 -05009if [ ! -e /aaf_cmd ]; then
10 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
11 chmod u+x /aaf_cmd
12fi
13
Instrumentalf0ddaf22018-10-03 22:29:23 -050014# Always need startup status...
15if [ ! -e "$DIR" ]; then
16 mkdir -p "$DIR"
17fi
18
Instrumental08e93402018-10-03 08:38:52 -050019function status {
Instrumental08e93402018-10-03 08:38:52 -050020 echo "$@"
21 echo "$@" > $DIR/aaf_cass
Instrumental08e93402018-10-03 08:38:52 -050022}
23
Instrumental1e3be602018-10-03 19:40:44 -050024function wait_start {
Instrumental08e93402018-10-03 08:38:52 -050025 sleep 10
26 status wait for cassandra to start
Instrumental1e3be602018-10-03 19:40:44 -050027 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
28 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
29 echo "Waiting for Cassandra to start... Sleep 10"
30 sleep 10
31 else
32 break
33 fi
34 done
35}
36
Instrumentalf0ddaf22018-10-03 22:29:23 -050037
Instrumental1e3be602018-10-03 19:40:44 -050038function wait_cql {
39 status wait for keyspace to be initialized
40 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 -050041 if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
Instrumental1e3be602018-10-03 19:40:44 -050042 break
43 else
44 echo "Waiting for Keyspaces to be loaded... Sleep 10"
45 sleep 10
46 fi
47 done
48}
49
Instrumentalf0ddaf22018-10-03 22:29:23 -050050function wait_ready {
51 status wait for cassandra to be fully ready
52 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
53 STATUS="$(cat $DIR/aaf_cass)"
54 if [ "$STATUS" = "ready" ]; then
55 break
56 else
57 echo "Waiting for Start, $STATUS... Sleep 10"
58 sleep 10
59 fi
60 done
61}
62
Instrumental1e3be602018-10-03 19:40:44 -050063function install_cql {
64 wait_start started
Instrumentalbc299c02018-09-25 06:42:31 -050065 # Now, make sure data exists
Instrumentale66f4282018-10-16 14:09:31 -050066 if [ ! -e $INSTALLED_VERSION ] && [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
67 /usr/bin/cqlsh -e 'DROP KEYSPACE authz'
68 fi
69 if [ -z "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" ]; then
70 status install
71 echo "Initializing Cassandra DB"
Instrumentalbc299c02018-09-25 06:42:31 -050072 echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following "
73 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
74 echo ""
75 echo " cd /opt/app/aaf/cass_init"
76 cd /opt/app/aaf/cass_init
77 echo " cqlsh -f keyspace.cql"
78 /usr/bin/cqlsh -f keyspace.cql
Instrumental08e93402018-10-03 08:38:52 -050079 status keyspace installed
Instrumentalbc299c02018-09-25 06:42:31 -050080 echo " cqlsh -f init.cql"
81 /usr/bin/cqlsh -f init.cql
Instrumental08e93402018-10-03 08:38:52 -050082 status data initialized
Instrumentalbc299c02018-09-25 06:42:31 -050083 echo ""
84 echo "The following will give you a temporary identity with which to start working, or emergency"
85 echo " cqlsh -f temp_identity.cql"
Instrumental2d18d8e2018-10-16 17:37:17 -050086 echo "casablanca" > $INSTALLED_VERSION
Instrumentale66f4282018-10-16 14:09:31 -050087 else
88 echo "Cassandra DB already includes 'authz' keyspace"
Instrumentalbc299c02018-09-25 06:42:31 -050089 fi
Instrumental08e93402018-10-03 08:38:52 -050090 status $1
Instrumentalbc299c02018-09-25 06:42:31 -050091}
92
Instrumental08e93402018-10-03 08:38:52 -050093function install_onap {
Instrumentala9391132018-10-16 12:34:12 -050094 echo " cd /opt/app/aaf/cass_init"
Instrumental94053612018-10-08 11:27:18 -050095 install_cql initialized
Instrumental50c23cc2018-10-31 02:40:03 -050096 if [ -e "$AAF_INIT_DATA" ]; then
97 echo "AAF Data already initialized on this Cassandra"
98 else
99 status prep data for bootstrapping
100 cd /opt/app/aaf/cass_init
101 status prep data
102 bash prep.sh
103 status push data to cassandra
104 bash push.sh
105 cd -
106 echo $(date) > $AAF_INIT_DATA
107 fi
Instrumental08e93402018-10-03 08:38:52 -0500108 status ready
109}
110
111case "$1" in
112 start)
113 # start install_cql in background, waiting for process to start
114 install_cql ready &
115
116 # Startup like normal
117 echo "Cassandra Startup"
118 /usr/local/bin/docker-entrypoint.sh
119 ;;
Instrumental1e3be602018-10-03 19:40:44 -0500120 wait)
121 # 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 -0500122 wait_ready
Instrumental1e3be602018-10-03 19:40:44 -0500123
Instrumental1e3be602018-10-03 19:40:44 -0500124 ;;
Instrumental08e93402018-10-03 08:38:52 -0500125 onap)
Instrumentale66f4282018-10-16 14:09:31 -0500126 cd /opt/app/aaf/cass_init
Instrumental08e93402018-10-03 08:38:52 -0500127 # start install_onap (which calls install_cql first) in background, waiting for process to start
Instrumental696d9dc2018-10-24 19:45:47 -0500128 install_onap &
Instrumental08e93402018-10-03 08:38:52 -0500129
130 # Startup like normal
131 echo "Cassandra Startup"
132 /usr/local/bin/docker-entrypoint.sh
Instrumentalbc299c02018-09-25 06:42:31 -0500133 ;;
134esac
135