02-install-database.sh 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/bin/bash
  2. # Get the directory where this script is located
  3. DATABASE_SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
  4. # Load configuration file
  5. source "$DATABASE_SCRIPT_DIR/00-config.sh"
  6. print "Installing database clusters..."
  7. # Install database clusters based on configuration
  8. [ "$ENABLE_POSTGRESQL" = true ] && print "Installing PostgreSQL cluster..." && helm upgrade --install pg-cluster kubeblocks/postgresql-cluster -f "$DATABASE_SCRIPT_DIR/postgresql/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION
  9. [ "$ENABLE_REDIS" = true ] && print "Installing Redis cluster..." && helm upgrade --install redis-cluster kubeblocks/redis-cluster -f "$DATABASE_SCRIPT_DIR/redis/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION
  10. [ "$ENABLE_ELASTICSEARCH" = true ] && print "Installing Elasticsearch cluster..." && helm upgrade --install es-cluster kubeblocks/elasticsearch-cluster -f "$DATABASE_SCRIPT_DIR/elasticsearch/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION
  11. [ "$ENABLE_QDRANT" = true ] && print "Installing Qdrant cluster..." && helm upgrade --install qdrant-cluster kubeblocks/qdrant-cluster -f "$DATABASE_SCRIPT_DIR/qdrant/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION
  12. [ "$ENABLE_MONGODB" = true ] && print "Installing MongoDB cluster..." && helm upgrade --install mongodb-cluster kubeblocks/mongodb-cluster -f "$DATABASE_SCRIPT_DIR/mongodb/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION
  13. [ "$ENABLE_NEO4J" = true ] && print "Installing Neo4j cluster..." && helm upgrade --install neo4j-cluster kubeblocks/neo4j-cluster -f "$DATABASE_SCRIPT_DIR/neo4j/values.yaml" --namespace $NAMESPACE --version $ADDON_CLUSTER_CHART_VERSION
  14. # Wait for databases to be ready
  15. print "Waiting for databases to be ready..."
  16. TIMEOUT=600 # Set timeout to 10 minutes
  17. START_TIME=$(date +%s)
  18. while true; do
  19. CURRENT_TIME=$(date +%s)
  20. ELAPSED=$((CURRENT_TIME - START_TIME))
  21. if [ $ELAPSED -gt $TIMEOUT ]; then
  22. print_error "Timeout waiting for databases to be ready. Please check database status manually and try again"
  23. exit 1
  24. fi
  25. # Build wait conditions for enabled databases
  26. WAIT_CONDITIONS=()
  27. [ "$ENABLE_POSTGRESQL" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=pg-cluster -n $NAMESPACE --timeout=10s")
  28. [ "$ENABLE_REDIS" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=redis-cluster -n $NAMESPACE --timeout=10s")
  29. [ "$ENABLE_ELASTICSEARCH" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=es-cluster -n $NAMESPACE --timeout=10s")
  30. [ "$ENABLE_QDRANT" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=qdrant-cluster -n $NAMESPACE --timeout=10s")
  31. [ "$ENABLE_MONGODB" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=mongodb-cluster -n $NAMESPACE --timeout=10s")
  32. [ "$ENABLE_NEO4J" = true ] && WAIT_CONDITIONS+=("kubectl wait --for=condition=ready pods -l app.kubernetes.io/instance=neo4j-cluster -n $NAMESPACE --timeout=10s")
  33. # Check if all enabled databases are ready
  34. ALL_READY=true
  35. for CONDITION in "${WAIT_CONDITIONS[@]}"; do
  36. if ! eval "$CONDITION &> /dev/null"; then
  37. ALL_READY=false
  38. break
  39. fi
  40. done
  41. if [ "$ALL_READY" = true ]; then
  42. print "All database pods are ready, continuing with deployment..."
  43. break
  44. fi
  45. print "Waiting for database pods to be ready (${ELAPSED}s elapsed)..."
  46. sleep 10
  47. done
  48. print_success "Database clusters installation completed!"
  49. print "Use the following command to check the status of installed clusters:"
  50. print "kubectl get clusters -n $NAMESPACE"