Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Engage normal Cass Init, then check for data installation |
| 4 | # |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 5 | DIR="/opt/app/aaf/status" |
Instrumental | 50c23cc | 2018-10-31 02:40:03 -0500 | [diff] [blame^] | 6 | INSTALLED_VERSION=/var/lib/cassandra/AAF_VERSION |
| 7 | AAF_INIT_DATA=/var/lib/cassandra/AAF_INIT_DATA |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 8 | |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 9 | if [ ! -e /aaf_cmd ]; then |
| 10 | ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd |
| 11 | chmod u+x /aaf_cmd |
| 12 | fi |
| 13 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 14 | # Always need startup status... |
| 15 | if [ ! -e "$DIR" ]; then |
| 16 | mkdir -p "$DIR" |
| 17 | fi |
| 18 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 19 | function status { |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 20 | echo "$@" |
| 21 | echo "$@" > $DIR/aaf_cass |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 22 | } |
| 23 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 24 | function wait_start { |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 25 | sleep 10 |
| 26 | status wait for cassandra to start |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 27 | 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 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 37 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 38 | function 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 |
Instrumental | 235dd9a | 2018-10-03 21:36:44 -0500 | [diff] [blame] | 41 | if [ -n "$(/usr/bin/cqlsh -e 'describe keyspaces' | grep authz)" ]; then |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 42 | break |
| 43 | else |
| 44 | echo "Waiting for Keyspaces to be loaded... Sleep 10" |
| 45 | sleep 10 |
| 46 | fi |
| 47 | done |
| 48 | } |
| 49 | |
Instrumental | f0ddaf2 | 2018-10-03 22:29:23 -0500 | [diff] [blame] | 50 | function 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 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 63 | function install_cql { |
| 64 | wait_start started |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 65 | # Now, make sure data exists |
Instrumental | e66f428 | 2018-10-16 14:09:31 -0500 | [diff] [blame] | 66 | 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" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 72 | 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 |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 79 | status keyspace installed |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 80 | echo " cqlsh -f init.cql" |
| 81 | /usr/bin/cqlsh -f init.cql |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 82 | status data initialized |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 83 | 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" |
Instrumental | 2d18d8e | 2018-10-16 17:37:17 -0500 | [diff] [blame] | 86 | echo "casablanca" > $INSTALLED_VERSION |
Instrumental | e66f428 | 2018-10-16 14:09:31 -0500 | [diff] [blame] | 87 | else |
| 88 | echo "Cassandra DB already includes 'authz' keyspace" |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 89 | fi |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 90 | status $1 |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 91 | } |
| 92 | |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 93 | function install_onap { |
Instrumental | a939113 | 2018-10-16 12:34:12 -0500 | [diff] [blame] | 94 | echo " cd /opt/app/aaf/cass_init" |
Instrumental | 9405361 | 2018-10-08 11:27:18 -0500 | [diff] [blame] | 95 | install_cql initialized |
Instrumental | 50c23cc | 2018-10-31 02:40:03 -0500 | [diff] [blame^] | 96 | 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 |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 108 | status ready |
| 109 | } |
| 110 | |
| 111 | case "$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 | ;; |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 120 | wait) |
| 121 | # 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] | 122 | wait_ready |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 123 | |
Instrumental | 1e3be60 | 2018-10-03 19:40:44 -0500 | [diff] [blame] | 124 | ;; |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 125 | onap) |
Instrumental | e66f428 | 2018-10-16 14:09:31 -0500 | [diff] [blame] | 126 | cd /opt/app/aaf/cass_init |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 127 | # 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] | 128 | install_onap & |
Instrumental | 08e9340 | 2018-10-03 08:38:52 -0500 | [diff] [blame] | 129 | |
| 130 | # Startup like normal |
| 131 | echo "Cassandra Startup" |
| 132 | /usr/local/bin/docker-entrypoint.sh |
Instrumental | bc299c0 | 2018-09-25 06:42:31 -0500 | [diff] [blame] | 133 | ;; |
| 134 | esac |
| 135 | |