blob: b26536d601994a1c2f09eecff81b6c91b391b719 [file] [log] [blame]
Instrumentalbc299c02018-09-25 06:42:31 -05001#!/bin/bash
Instrumental7a1817b2018-11-05 11:11:15 -06002#########
3# ============LICENSE_START====================================================
4# org.onap.aaf
5# ===========================================================================
6# Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
7# ===========================================================================
8# Licensed under the Apache License, Version 2.0 (the "License");
9# you may not use this file except in compliance with the License.
10# You may obtain a copy of the License at
11#
12# http://www.apache.org/licenses/LICENSE-2.0
13#
14# Unless required by applicable law or agreed to in writing, software
15# distributed under the License is distributed on an "AS IS" BASIS,
16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17# See the License for the specific language governing permissions and
18# limitations under the License.
19# ============LICENSE_END====================================================
20#
Instrumentalbc299c02018-09-25 06:42:31 -050021#
22# Engage normal Cass Init, then check for data installation
23#
Instrumental08e93402018-10-03 08:38:52 -050024DIR="/opt/app/aaf/status"
Instrumental50c23cc2018-10-31 02:40:03 -050025INSTALLED_VERSION=/var/lib/cassandra/AAF_VERSION
26AAF_INIT_DATA=/var/lib/cassandra/AAF_INIT_DATA
Instrumental08e93402018-10-03 08:38:52 -050027
Instrumentalbc299c02018-09-25 06:42:31 -050028if [ ! -e /aaf_cmd ]; then
29 ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
30 chmod u+x /aaf_cmd
31fi
32
Instrumentalf0ddaf22018-10-03 22:29:23 -050033# Always need startup status...
34if [ ! -e "$DIR" ]; then
35 mkdir -p "$DIR"
Instrumental27afb022019-02-07 16:36:56 -060036 chmod 777 $DIR
Instrumentalf0ddaf22018-10-03 22:29:23 -050037fi
38
Instrumental08e93402018-10-03 08:38:52 -050039function status {
Instrumental08e93402018-10-03 08:38:52 -050040 echo "$@"
Instrumental12414fe2019-01-22 10:27:32 -060041 echo "$@" > $DIR/aaf-cass
Instrumental08e93402018-10-03 08:38:52 -050042}
43
Instrumental1e3be602018-10-03 19:40:44 -050044function wait_start {
Instrumental08e93402018-10-03 08:38:52 -050045 sleep 10
46 status wait for cassandra to start
Instrumental1e3be602018-10-03 19:40:44 -050047 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
48 if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then
49 echo "Waiting for Cassandra to start... Sleep 10"
50 sleep 10
51 else
Instrumentale56243c2019-02-26 06:45:39 -060052 status cassandra started
Instrumental1e3be602018-10-03 19:40:44 -050053 break
54 fi
55 done
Instrumentale56243c2019-02-26 06:45:39 -060056 # Logs state Cassandra is up. Now use cqlsh to ensure responsive
57 echo "Cassandra started, wait until it is responsive"
58 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
59 if [ -z "$(cqlsh -e 'describe keyspaces')" ]; then
60 echo "Waiting for Cassandra to be responsive... Sleep 10"
61 sleep 10
62 else
63 echo "Cassandra responded"
64 status cassandra responsive
65 break
66 fi
67 done
Instrumental1e3be602018-10-03 19:40:44 -050068}
69
Instrumentalf0ddaf22018-10-03 22:29:23 -050070
Instrumental1e3be602018-10-03 19:40:44 -050071function wait_cql {
72 status wait for keyspace to be initialized
73 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 -050074 if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
Instrumental1e3be602018-10-03 19:40:44 -050075 break
76 else
77 echo "Waiting for Keyspaces to be loaded... Sleep 10"
78 sleep 10
79 fi
80 done
81}
82
Instrumentalf0ddaf22018-10-03 22:29:23 -050083function wait_ready {
84 status wait for cassandra to be fully ready
85 for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
Instrumental12414fe2019-01-22 10:27:32 -060086 STATUS="$(cat $DIR/aaf-cass)"
Instrumentalf0ddaf22018-10-03 22:29:23 -050087 if [ "$STATUS" = "ready" ]; then
88 break
89 else
90 echo "Waiting for Start, $STATUS... Sleep 10"
91 sleep 10
92 fi
93 done
94}
95
Instrumental1e3be602018-10-03 19:40:44 -050096function install_cql {
Instrumentale56243c2019-02-26 06:45:39 -060097 wait_start cassandra responsive
Instrumentalbc299c02018-09-25 06:42:31 -050098 # Now, make sure data exists
Instrumentale66f4282018-10-16 14:09:31 -050099 if [ ! -e $INSTALLED_VERSION ] && [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then
Instrumentalc5705cd2019-02-26 13:12:00 -0600100 /usr/bin/cqlsh --request-timeout=60 -e 'DROP KEYSPACE authz'
Instrumentale66f4282018-10-16 14:09:31 -0500101 fi
Instrumentale56243c2019-02-26 06:45:39 -0600102
Instrumentalc5705cd2019-02-26 13:12:00 -0600103 if [ -z "`/usr/bin/cqlsh --request-timeout 60 -e 'describe keyspaces' | grep authz`" ]; then
Instrumentale66f4282018-10-16 14:09:31 -0500104 status install
105 echo "Initializing Cassandra DB"
Instrumental12414fe2019-01-22 10:27:32 -0600106 echo "Docker Installed Basic Cassandra on aaf.cass. Executing the following "
Instrumentalbc299c02018-09-25 06:42:31 -0500107 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
108 echo ""
109 echo " cd /opt/app/aaf/cass_init"
110 cd /opt/app/aaf/cass_init
111 echo " cqlsh -f keyspace.cql"
Instrumentale56243c2019-02-26 06:45:39 -0600112 /usr/bin/cqlsh --request-timeout=100 -f keyspace.cql
Instrumental08e93402018-10-03 08:38:52 -0500113 status keyspace installed
Instrumentalbc299c02018-09-25 06:42:31 -0500114 echo " cqlsh -f init.cql"
Instrumentale56243c2019-02-26 06:45:39 -0600115 /usr/bin/cqlsh --request-timeout=100 -f init.cql
Instrumental08e93402018-10-03 08:38:52 -0500116 status data initialized
Instrumentalbc299c02018-09-25 06:42:31 -0500117 echo ""
118 echo "The following will give you a temporary identity with which to start working, or emergency"
119 echo " cqlsh -f temp_identity.cql"
Instrumental2d18d8e2018-10-16 17:37:17 -0500120 echo "casablanca" > $INSTALLED_VERSION
Instrumentale66f4282018-10-16 14:09:31 -0500121 else
122 echo "Cassandra DB already includes 'authz' keyspace"
Instrumentalbc299c02018-09-25 06:42:31 -0500123 fi
Instrumental08e93402018-10-03 08:38:52 -0500124 status $1
Instrumentalbc299c02018-09-25 06:42:31 -0500125}
126
Instrumental08e93402018-10-03 08:38:52 -0500127function install_onap {
Instrumentala9391132018-10-16 12:34:12 -0500128 echo " cd /opt/app/aaf/cass_init"
Instrumental94053612018-10-08 11:27:18 -0500129 install_cql initialized
Instrumental50c23cc2018-10-31 02:40:03 -0500130 if [ -e "$AAF_INIT_DATA" ]; then
131 echo "AAF Data already initialized on this Cassandra"
132 else
133 status prep data for bootstrapping
134 cd /opt/app/aaf/cass_init
135 status prep data
136 bash prep.sh
137 status push data to cassandra
138 bash push.sh
139 cd -
140 echo $(date) > $AAF_INIT_DATA
141 fi
Instrumental08e93402018-10-03 08:38:52 -0500142 status ready
143}
144
145case "$1" in
146 start)
147 # start install_cql in background, waiting for process to start
148 install_cql ready &
149
150 # Startup like normal
151 echo "Cassandra Startup"
Instrumental27afb022019-02-07 16:36:56 -0600152 exec /usr/local/bin/docker-entrypoint.sh
Instrumental08e93402018-10-03 08:38:52 -0500153 ;;
Instrumental1e3be602018-10-03 19:40:44 -0500154 wait)
155 # 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 -0500156 wait_ready
Instrumental1e3be602018-10-03 19:40:44 -0500157
Instrumental1e3be602018-10-03 19:40:44 -0500158 ;;
Instrumental08e93402018-10-03 08:38:52 -0500159 onap)
Instrumentale66f4282018-10-16 14:09:31 -0500160 cd /opt/app/aaf/cass_init
Instrumental08e93402018-10-03 08:38:52 -0500161 # start install_onap (which calls install_cql first) in background, waiting for process to start
Instrumental696d9dc2018-10-24 19:45:47 -0500162 install_onap &
Instrumental08e93402018-10-03 08:38:52 -0500163
164 # Startup like normal
165 echo "Cassandra Startup"
root40fad642019-02-25 17:23:37 -0500166 if ! cat /etc/cassandra/cassandra.yaml | grep "write_request_timeout_in_ms: 20000"; then
167 sed -i 's/write_request_timeout_in_ms: 2000/write_request_timeout_in_ms: 20000/' /etc/cassandra/cassandra.yaml
168 fi
Instrumental27afb022019-02-07 16:36:56 -0600169 exec /usr/local/bin/docker-entrypoint.sh
Instrumentalbc299c02018-09-25 06:42:31 -0500170 ;;
171esac
172