#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" # shellcheck disable=SC1091 source "$SCRIPT_DIR/common.sh" BUILD_SCRIPT="$SCRIPT_DIR/build_local_backend.sh" PUBLISH_SCRIPT="$SCRIPT_DIR/publish_local_nacos_configs.sh" SKIP_BUILD=false INFRA_ONLY=false usage() { cat <<'EOF' 用法: ./start_local_services.sh ./start_local_services.sh --skip-build ./start_local_services.sh --infra-only EOF } while [ "$#" -gt 0 ]; do case "$1" in --skip-build) SKIP_BUILD=true ;; --infra-only) INFRA_ONLY=true ;; -h|--help) usage exit 0 ;; *) echo "unknown option: $1" >&2 usage >&2 exit 1 ;; esac shift done load_local_env wait_for_docker if [ "$SKIP_BUILD" = false ] && [ "$INFRA_ONLY" = false ]; then java_major="$(java_major_version || true)" if [ "$java_major" = "17" ]; then "$BUILD_SCRIPT" else if all_local_java_jars_present; then echo "detected Java ${java_major:-unknown}; local rebuild requires JDK 17" >&2 echo "to intentionally reuse the current jars, rerun ./start_local_services.sh --skip-build" >&2 else echo "local Java jars are missing and the current machine is not using JDK 17" >&2 echo "please switch to JDK 17 and rerun ./start_local_services.sh, or prebuild the jars first" >&2 fi exit 1 fi fi compose up -d mysql redis mongo nacos zookeeper if ! local_rocketmq_disabled; then compose up -d --remove-orphans rocketmq-namesrv rocketmq-init rocketmq-broker rocketmq-proxy fi wait_container_healthy chatapp3-local-mysql 120 wait_container_healthy chatapp3-local-redis 120 wait_container_healthy chatapp3-local-mongo 120 echo "waiting for nacos..." require_env LIKEI_LOCAL_NACOS_PORT wait_http "http://127.0.0.1:${LIKEI_LOCAL_NACOS_PORT}/nacos/" 120 wait_local_rocketmq "$PUBLISH_SCRIPT" if [ "$INFRA_ONLY" = false ]; then compose up -d --force-recreate \ gateway auth external other live order wallet console visual-monitor scheduling game-fruit golang for service in gateway auth other live order wallet console external visual-monitor scheduling game-fruit golang; do wait_service_port "$service" 120 done fi compose ps