#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" ENV_NAME="${1:-prod}" export APP_ENV="$ENV_NAME" cd "$ROOT_DIR" if [ -f ".env.$ENV_NAME" ]; then true elif [ -f "server/.env.$ENV_NAME" ]; then true else echo ".env.$ENV_NAME not found" >&2 exit 1 fi mkdir -p log cd "$ROOT_DIR/server" go build -o "bin/marketing-data-server" "./cmd/server" cd "$ROOT_DIR" TARGET="$ROOT_DIR/server/bin/marketing-data-server" nohup env APP_ENV="$ENV_NAME" "$TARGET" > "$ROOT_DIR/log/server.out" 2>&1 & echo $! > "$ROOT_DIR/server/bin/server.pid" echo "started: $TARGET pid $(cat "$ROOT_DIR/server/bin/server.pid")"