智慧水务管理系统 - 精河县供水工程综合管理平台

start.sh 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #!/bin/bash
  2. # Water Management System IoT Layer Startup Script
  3. set -e
  4. echo "🚀 Starting Water Management System IoT Layer..."
  5. # Colors for output
  6. RED='\033[0;31m'
  7. GREEN='\033[0;32m'
  8. YELLOW='\033[1;33m'
  9. NC='\033[0m' # No Color
  10. # Function to print colored output
  11. print_status() {
  12. echo -e "${GREEN}[INFO]${NC} $1"
  13. }
  14. print_warning() {
  15. echo -e "${YELLOW}[WARNING]${NC} $1"
  16. }
  17. print_error() {
  18. echo -e "${RED}[ERROR]${NC} $1"
  19. }
  20. # Check if Docker is installed
  21. if ! command -v docker &> /dev/null; then
  22. print_error "Docker is not installed. Please install Docker first."
  23. exit 1
  24. fi
  25. # Check if Docker Compose is installed
  26. if ! command -v docker-compose &> /dev/null; then
  27. print_error "Docker Compose is not installed. Please install Docker Compose first."
  28. exit 1
  29. fi
  30. # Navigate to project directory
  31. cd "$(dirname "$0")/.."
  32. print_status "Building and starting Docker services..."
  33. # Start Docker services
  34. docker-compose up -d
  35. print_status "Waiting for services to start..."
  36. # Wait for PostgreSQL to be ready
  37. print_status "Waiting for PostgreSQL..."
  38. until docker-compose exec postgres pg_isready -U water_user -d water_management; do
  39. sleep 2
  40. done
  41. print_status "PostgreSQL is ready!"
  42. # Wait for Kafka to be ready
  43. print_status "Waiting for Kafka..."
  44. until docker-compose exec kafka kafka-topics.sh --list --bootstrap-server localhost:9092 &> /dev/null; do
  45. sleep 2
  46. done
  47. print_status "Kafka is ready!"
  48. # Wait for Redis to be ready
  49. print_status "Waiting for Redis..."
  50. until docker-compose exec redis redis-cli ping | grep -q PONG; do
  51. sleep 2
  52. done
  53. print_status "Redis is ready!"
  54. # Wait for EMQX to be ready
  55. print_status "Waiting for EMQX..."
  56. until curl -s http://localhost:18083/api/v4/status | grep -q "running"; do
  57. sleep 2
  58. done
  59. print_status "EMQX is ready!"
  60. print_status "Starting Spring Boot application..."
  61. # Build and run the application
  62. mvn clean package -DskipTests
  63. java -jar target/water-management-system-1.0.0-SNAPSHOT.jar &
  64. SPRING_BOOT_PID=$!
  65. print_status "Spring Boot application started with PID: $SPRING_BOOT_PID"
  66. print_status "Waiting for Spring Boot application to be ready..."
  67. # Wait for Spring Boot to be ready
  68. until curl -s http://localhost:8080/actuator/health | grep -q "UP"; do
  69. sleep 2
  70. done
  71. print_status "Water Management System IoT Layer is ready!"
  72. print_status "Dashboard: http://localhost:8080"
  73. print_status "EMQX Dashboard: http://localhost:18083 (admin/public)"
  74. print_status "Kafka UI: http://localhost:8080 (if available)"
  75. # Store the PID for potential shutdown
  76. echo $SPRING_BOOT_PID > .spring-boot.pid
  77. echo ""
  78. echo "🎉 System started successfully!"
  79. echo ""
  80. echo "Useful commands:"
  81. echo "- View logs: docker-compose logs -f"
  82. echo "- Stop services: docker-compose down"
  83. echo "- Stop Spring Boot: kill \$(cat .spring-boot.pid)"
  84. echo "- Check health: curl http://localhost:8080/actuator/health"