Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 1 | #!/bin/bash |
Instrumental | 7a1817b | 2018-11-05 11:11:15 -0600 | [diff] [blame^] | 2 | ######### |
| 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 | # |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 21 | # |
| 22 | # Engage normal Cass Init, then check for data installation |
| 23 | # |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 24 | DIR="/opt/app/aaf/status" |
Instrumental | 50c23cc | 2018-10-31 02:40:03 -0500 | [diff] [blame] | 25 | INSTALLED_VERSION=/var/lib/cassandra/AAF_VERSION |
| 26 | AAF_INIT_DATA=/var/lib/cassandra/AAF_INIT_DATA |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 27 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 28 | if [ ! -e /aaf_cmd ]; then |
| 29 | ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd |
| 30 | chmod u+x /aaf_cmd |
| 31 | fi |
| 32 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 33 | # Always need startup status... |
| 34 | if [ ! -e "$DIR" ]; then |
| 35 | mkdir -p "$DIR" |
| 36 | fi |
| 37 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 38 | function status { |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 39 | echo "$@" |
| 40 | echo "$@" > $DIR/aaf_cass |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 41 | } |
| 42 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 43 | function wait_start { |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 44 | sleep 10 |
| 45 | status wait for cassandra to start |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 46 | for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
| 47 | if [ -z "$(grep 'listening for CQL clients' /var/log/cassandra/system.log)" ]; then |
| 48 | echo "Waiting for Cassandra to start... Sleep 10" |
| 49 | sleep 10 |
| 50 | else |
| 51 | break |
| 52 | fi |
| 53 | done |
| 54 | } |
| 55 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 56 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 57 | function wait_cql { |
| 58 | status wait for keyspace to be initialized |
| 59 | for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
Instrumental | 235dd9a | 2018-10-03 21:36:44 -0500 | [diff] [blame] | 60 | if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 61 | break |
| 62 | else |
| 63 | echo "Waiting for Keyspaces to be loaded... Sleep 10" |
| 64 | sleep 10 |
| 65 | fi |
| 66 | done |
| 67 | } |
| 68 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 69 | function wait_ready { |
| 70 | status wait for cassandra to be fully ready |
| 71 | for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do |
| 72 | STATUS="$(cat $DIR/aaf_cass)" |
| 73 | if [ "$STATUS" = "ready" ]; then |
| 74 | break |
| 75 | else |
| 76 | echo "Waiting for Start, $STATUS... Sleep 10" |
| 77 | sleep 10 |
| 78 | fi |
| 79 | done |
| 80 | } |
| 81 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 82 | function install_cql { |
| 83 | wait_start started |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 84 | # Now, make sure data exists |
Instrumental | e66f428 | 2018-10-16 14:09:31 -0500 | [diff] [blame] | 85 | if [ ! -e $INSTALLED_VERSION ] && [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then |
| 86 | /usr/bin/cqlsh -e 'DROP KEYSPACE authz' |
| 87 | fi |
| 88 | if [ -z "`/usr/bin/cqlsh -e 'describe keyspaces' | grep authz`" ]; then |
| 89 | status install |
| 90 | echo "Initializing Cassandra DB" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 91 | echo "Docker Installed Basic Cassandra on aaf_cass. Executing the following " |
| 92 | echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently" |
| 93 | echo "" |
| 94 | echo " cd /opt/app/aaf/cass_init" |
| 95 | cd /opt/app/aaf/cass_init |
| 96 | echo " cqlsh -f keyspace.cql" |
| 97 | /usr/bin/cqlsh -f keyspace.cql |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 98 | status keyspace installed |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 99 | echo " cqlsh -f init.cql" |
| 100 | /usr/bin/cqlsh -f init.cql |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 101 | status data initialized |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 102 | echo "" |
| 103 | echo "The following will give you a temporary identity with which to start working, or emergency" |
| 104 | echo " cqlsh -f temp_identity.cql" |
Instrumental | 2d18d8e | 2018-10-16 17:37:17 -0500 | [diff] [blame] | 105 | echo "casablanca" > $INSTALLED_VERSION |
Instrumental | e66f428 | 2018-10-16 14:09:31 -0500 | [diff] [blame] | 106 | else |
| 107 | echo "Cassandra DB already includes 'authz' keyspace" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 108 | fi |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 109 | status $1 |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 110 | } |
| 111 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 112 | function install_onap { |
Instrumental | a939113 | 2018-10-16 12:34:12 -0500 | [diff] [blame] | 113 | echo " cd /opt/app/aaf/cass_init" |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 114 | install_cql initialized |
Instrumental | 50c23cc | 2018-10-31 02:40:03 -0500 | [diff] [blame] | 115 | if [ -e "$AAF_INIT_DATA" ]; then |
| 116 | echo "AAF Data already initialized on this Cassandra" |
| 117 | else |
| 118 | status prep data for bootstrapping |
| 119 | cd /opt/app/aaf/cass_init |
| 120 | status prep data |
| 121 | bash prep.sh |
| 122 | status push data to cassandra |
| 123 | bash push.sh |
| 124 | cd - |
| 125 | echo $(date) > $AAF_INIT_DATA |
| 126 | fi |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 127 | status ready |
| 128 | } |
| 129 | |
| 130 | case "$1" in |
| 131 | start) |
| 132 | # start install_cql in background, waiting for process to start |
| 133 | install_cql ready & |
| 134 | |
| 135 | # Startup like normal |
| 136 | echo "Cassandra Startup" |
| 137 | /usr/local/bin/docker-entrypoint.sh |
| 138 | ;; |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 139 | wait) |
| 140 | # Wait for initialization. This can be called from Docker only as a check to make sure it is ready |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 141 | wait_ready |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 142 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 143 | ;; |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 144 | onap) |
Instrumental | e66f428 | 2018-10-16 14:09:31 -0500 | [diff] [blame] | 145 | cd /opt/app/aaf/cass_init |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 146 | # start install_onap (which calls install_cql first) in background, waiting for process to start |
Instrumental | 696d9dc | 2018-10-24 19:45:47 -0500 | [diff] [blame] | 147 | install_onap & |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 148 | |
| 149 | # Startup like normal |
| 150 | echo "Cassandra Startup" |
| 151 | /usr/local/bin/docker-entrypoint.sh |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 152 | ;; |
| 153 | esac |
| 154 | |