Kickstart Cassandra, read logs
[aaf/authz.git] / auth / auth-cass / docker / dinstall.sh
1 #!/bin/bash 
2
3 if [ "`docker ps -a | grep aaf_cass`" == "" ]; then
4   docker run --name aaf_cass  -d cassandra:3.11
5   echo "aaf_cass Starting"
6   echo "Check for running Docker Container aaf_cass, then run again."
7   # we have to exit here so that the calling script can load CQL files
8   exit
9 else
10   for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
11      if [ "`docker container logs aaf_cass | grep 'listening for CQL clients'`" == "" ]; then
12                 echo "Sleep 10"
13         sleep 10
14      else 
15                 YESCQL="yes"
16         break
17      fi
18   done
19 fi 
20
21 if [ "$YESCQL" == "" ]; then
22   echo "CQL Never started... exiting"
23   exit
24 fi
25
26 docker exec aaf_cass mkdir -p /opt/app/cass_init
27 docker cp "../src/main/cql/." aaf_cass:/opt/app/cass_init
28
29 echo "Docker Installed Basic Cassandra on aaf_cass.  Executing the following "
30 echo "NOTE: This creator provided is only a Single Instance. For more complex Cassandra, create independently"
31 echo ""
32 echo " cd /opt/app/cass_init"  
33 echo " cqlsh -u root -p root -f keyspace.cql"
34 echo " cqlsh -u root -p root -f init.cql"
35 echo " cqlsh -u root -p root -f osaaf.cql"
36 echo ""
37 echo "The following will give you a temporary identity with which to start working, or emergency"
38 echo " cqlsh -u root -p root -f temp_identity.cql"
39 echo "Sleeping for 20 seconds"
40
41 echo "Create Keyspaces and Tables"
42 docker exec -it aaf_cass bash -c '\
43 cd /opt/app/cass_init; \
44 echo "Creating Keyspace";cqlsh -u root -p root -f keyspace.cql;\
45 echo "Creating init";cqlsh -u root -p root -f init.cql;\
46 echo "Creating osaaf";cqlsh -u root -p root -f osaaf.cql;\
47 echo "Creating temp Identity";cqlsh -u root -p root -f temp_identity.cql'
48
49 echo "Inspecting aafcassadra.  Use to get the IP address to update org.osaaf.cassandra.props"
50 docker inspect aaf_cass | grep '"IPAddress' | head -1