Spaces:
Sleeping
Sleeping
| set -euo pipefail | |
| ROOT_DIR="/app" | |
| LOG_DIR="${ROOT_DIR}/logs" | |
| MONGO_DATA_DIR="/data/db" | |
| mkdir -p "${LOG_DIR}" "${MONGO_DATA_DIR}" | |
| cleanup() { | |
| if [[ -n "${SERVICE_PIDS[*]-}" ]]; then | |
| for pid in "${SERVICE_PIDS[@]}"; do | |
| if kill -0 "${pid}" 2>/dev/null; then | |
| kill "${pid}" 2>/dev/null || true | |
| fi | |
| done | |
| fi | |
| mongod --shutdown --dbpath "${MONGO_DATA_DIR}" >/dev/null 2>&1 || true | |
| } | |
| trap cleanup EXIT | |
| log() { | |
| echo "[$(date '+%Y-%m-%dT%H:%M:%S%z')] $*" | |
| } | |
| wait_for_port() { | |
| local host="$1" | |
| local port="$2" | |
| local retries="${3:-60}" | |
| local delay="${4:-2}" | |
| for ((i=0; i<retries; i++)); do | |
| if nc -z "${host}" "${port}" 2>/dev/null; then | |
| return 0 | |
| fi | |
| sleep "${delay}" | |
| done | |
| log "❌ Timed out waiting for ${host}:${port}" | |
| return 1 | |
| } | |
| wait_for_http() { | |
| local url="$1" | |
| local retries="${2:-60}" | |
| local delay="${3:-2}" | |
| for ((i=0; i<retries; i++)); do | |
| if curl -fsS "${url}" >/dev/null 2>&1; then | |
| return 0 | |
| fi | |
| sleep "${delay}" | |
| done | |
| log "❌ Timed out waiting for ${url}" | |
| return 1 | |
| } | |
| start_service() { | |
| local service_dir="$1" | |
| local jar_name="$2" | |
| shift 2 | |
| ( | |
| cd "${ROOT_DIR}/${service_dir}" | |
| env "$@" java -jar "build/libs/${jar_name}" \ | |
| >>"${LOG_DIR}/${service_dir}.log" 2>&1 & | |
| echo $! | |
| ) | |
| } | |
| log "Starting MongoDB daemon" | |
| mongod --dbpath "${MONGO_DATA_DIR}" --bind_ip_all --logpath "${LOG_DIR}/mongodb.log" --fork | |
| wait_for_port "127.0.0.1" 27017 120 1 | |
| SERVICE_PIDS=() | |
| log "Starting Eureka server" | |
| PID=$(start_service "EurekaServerConfiguration" "eureka-server.jar" \ | |
| SERVER_PORT=8085 \ | |
| SPRING_PROFILES_ACTIVE=docker \ | |
| ZIPKIN_BASE_URL=) | |
| SERVICE_PIDS+=(${PID}) | |
| wait_for_http "http://127.0.0.1:8085/actuator/health" | |
| log "Starting User service" | |
| PID=$(start_service "TaskUserService" "task-user-service.jar" \ | |
| SERVER_PORT=8081 \ | |
| SPRING_PROFILES_ACTIVE=docker \ | |
| SPRING_APP_NAME=USER-SERVICE \ | |
| EUREKA_SERVER_URI=http://127.0.0.1:8085/eureka \ | |
| MONGODB_URI=mongodb://127.0.0.1:27017/users \ | |
| ZIPKIN_BASE_URL= \ | |
| TASK_ALLOWED_ORIGINS=* \ | |
| TASK_ALLOW_CREDENTIALS=false) | |
| SERVICE_PIDS+=(${PID}) | |
| wait_for_http "http://127.0.0.1:8081/actuator/health" | |
| log "Starting Task service" | |
| PID=$(start_service "TaskService" "task-service.jar" \ | |
| SERVER_PORT=8082 \ | |
| SPRING_PROFILES_ACTIVE=docker \ | |
| SPRING_APP_NAME=TASK-SERVICE \ | |
| EUREKA_SERVER_URI=http://127.0.0.1:8085/eureka \ | |
| MONGODB_URI=mongodb://127.0.0.1:27017/tasks \ | |
| ZIPKIN_BASE_URL=) | |
| SERVICE_PIDS+=(${PID}) | |
| wait_for_http "http://127.0.0.1:8082/actuator/health" | |
| log "Starting Task Submission service" | |
| PID=$(start_service "TaskSubmissionService" "task-submission-service.jar" \ | |
| SERVER_PORT=8083 \ | |
| SPRING_PROFILES_ACTIVE=docker \ | |
| SPRING_APP_NAME=TASK-SUBMISSION-SERVICE \ | |
| EUREKA_SERVER_URI=http://127.0.0.1:8085/eureka \ | |
| MONGODB_URI=mongodb://127.0.0.1:27017/submissions \ | |
| ZIPKIN_BASE_URL=) | |
| SERVICE_PIDS+=(${PID}) | |
| wait_for_http "http://127.0.0.1:8083/actuator/health" | |
| log "Starting API Gateway" | |
| PID=$(start_service "APIGateWay" "api-gateway.jar" \ | |
| SERVER_PORT=8090 \ | |
| SPRING_PROFILES_ACTIVE=docker \ | |
| EUREKA_SERVER_URI=http://127.0.0.1:8085/eureka \ | |
| ZIPKIN_BASE_URL= \ | |
| GATEWAY_ALLOWED_ORIGIN_1=* \ | |
| GATEWAY_ALLOWED_ORIGIN_PATTERN=*) | |
| SERVICE_PIDS+=(${PID}) | |
| wait_for_http "http://127.0.0.1:8090/actuator/health" | |
| log "All backend services are up. Launching UI server" | |
| cd "${ROOT_DIR}/task-management-ui" | |
| export INTERNAL_API_URL="http://127.0.0.1:8090" | |
| exec node server.js | |