| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #!/bin/bash
-
- # Water Management System IoT Layer Startup Script
-
- set -e
-
- echo "🚀 Starting Water Management System IoT Layer..."
-
- # Colors for output
- RED='\033[0;31m'
- GREEN='\033[0;32m'
- YELLOW='\033[1;33m'
- NC='\033[0m' # No Color
-
- # Function to print colored output
- print_status() {
- echo -e "${GREEN}[INFO]${NC} $1"
- }
-
- print_warning() {
- echo -e "${YELLOW}[WARNING]${NC} $1"
- }
-
- print_error() {
- echo -e "${RED}[ERROR]${NC} $1"
- }
-
- # Check if Docker is installed
- if ! command -v docker &> /dev/null; then
- print_error "Docker is not installed. Please install Docker first."
- exit 1
- fi
-
- # Check if Docker Compose is installed
- if ! command -v docker-compose &> /dev/null; then
- print_error "Docker Compose is not installed. Please install Docker Compose first."
- exit 1
- fi
-
- # Navigate to project directory
- cd "$(dirname "$0")/.."
-
- print_status "Building and starting Docker services..."
-
- # Start Docker services
- docker-compose up -d
-
- print_status "Waiting for services to start..."
-
- # Wait for PostgreSQL to be ready
- print_status "Waiting for PostgreSQL..."
- until docker-compose exec postgres pg_isready -U water_user -d water_management; do
- sleep 2
- done
- print_status "PostgreSQL is ready!"
-
- # Wait for Kafka to be ready
- print_status "Waiting for Kafka..."
- until docker-compose exec kafka kafka-topics.sh --list --bootstrap-server localhost:9092 &> /dev/null; do
- sleep 2
- done
- print_status "Kafka is ready!"
-
- # Wait for Redis to be ready
- print_status "Waiting for Redis..."
- until docker-compose exec redis redis-cli ping | grep -q PONG; do
- sleep 2
- done
- print_status "Redis is ready!"
-
- # Wait for EMQX to be ready
- print_status "Waiting for EMQX..."
- until curl -s http://localhost:18083/api/v4/status | grep -q "running"; do
- sleep 2
- done
- print_status "EMQX is ready!"
-
- print_status "Starting Spring Boot application..."
-
- # Build and run the application
- mvn clean package -DskipTests
-
- java -jar target/water-management-system-1.0.0-SNAPSHOT.jar &
- SPRING_BOOT_PID=$!
-
- print_status "Spring Boot application started with PID: $SPRING_BOOT_PID"
-
- print_status "Waiting for Spring Boot application to be ready..."
-
- # Wait for Spring Boot to be ready
- until curl -s http://localhost:8080/actuator/health | grep -q "UP"; do
- sleep 2
- done
-
- print_status "Water Management System IoT Layer is ready!"
- print_status "Dashboard: http://localhost:8080"
- print_status "EMQX Dashboard: http://localhost:18083 (admin/public)"
- print_status "Kafka UI: http://localhost:8080 (if available)"
-
- # Store the PID for potential shutdown
- echo $SPRING_BOOT_PID > .spring-boot.pid
-
- echo ""
- echo "🎉 System started successfully!"
- echo ""
- echo "Useful commands:"
- echo "- View logs: docker-compose logs -f"
- echo "- Stop services: docker-compose down"
- echo "- Stop Spring Boot: kill \$(cat .spring-boot.pid)"
- echo "- Check health: curl http://localhost:8080/actuator/health"
|