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