Files
platforms/scripts/run_backend.sh

45 lines
1.3 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
set -Eeuo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
BACKEND_DIR="${PROJECT_ROOT}/backend/api"
RUNTIME_CONFIG_ROOT=""
BACKEND_PID=""
cleanup() {
trap - EXIT INT TERM
if [[ -n "${BACKEND_PID}" ]] && kill -0 "${BACKEND_PID}" 2>/dev/null; then
kill "${BACKEND_PID}" 2>/dev/null || true
wait "${BACKEND_PID}" 2>/dev/null || true
fi
if [[ -n "${RUNTIME_CONFIG_ROOT}" ]]; then
rm -f "${RUNTIME_CONFIG_ROOT}/etc/heqi_dev.yaml"
rmdir "${RUNTIME_CONFIG_ROOT}/etc" "${RUNTIME_CONFIG_ROOT}" 2>/dev/null || true
fi
}
if ! command -v go >/dev/null 2>&1; then
echo "缺少命令go" >&2
exit 1
fi
export BSM_RuntimeMode="${BSM_RuntimeMode:-dev}"
export BSM_JwtSecretKey="${BSM_JwtSecretKey:-local-dev-key-16}"
if [[ -z "${BSM_Prefix:-}" ]]; then
RUNTIME_CONFIG_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/heqi-platform-backend.XXXXXX")"
mkdir -p "${RUNTIME_CONFIG_ROOT}/etc"
cp "${BACKEND_DIR}/etc/platform_dev.yaml" "${RUNTIME_CONFIG_ROOT}/etc/heqi_dev.yaml"
export BSM_Prefix="${RUNTIME_CONFIG_ROOT}"
fi
trap cleanup EXIT INT TERM
echo "启动平台后端http://localhost:12426/heqi/platform/v1"
cd "${BACKEND_DIR}"
go run ./cmd/main/main.go &
BACKEND_PID=$!
wait "${BACKEND_PID}"