| 1 | #!/usr/bin/env bash |
| 2 | # Production process entrypoint for systemd. |
| 3 | # Always updates the tree before starting Node so crash/power-loss recovery |
| 4 | # can pick up a fix from origin (intentional — do not skip pull on crash). |
| 5 | set -euo pipefail |
| 6 | |
| 7 | REPO="${QUESTWARD_REPO:-${TILE_MMO_REPO:-$(cd "$(dirname "$0")/.." && pwd)}}" |
| 8 | BRANCH="${QUESTWARD_GIT_BRANCH:-${TILE_MMO_GIT_BRANCH:-master}}" |
| 9 | cd "$REPO" |
| 10 | |
| 11 | echo "[deploy] Working tree: $REPO (branch $BRANCH)" |
| 12 | git fetch origin "$BRANCH" |
| 13 | git reset --hard "origin/$BRANCH" |
| 14 | git clean -fd |
| 15 | git pull --ff-only origin "$BRANCH" || true |
| 16 | |
| 17 | DEPLOY_DIR="$(cd "$(dirname "$0")" && pwd)" |
| 18 | chmod +x "$DEPLOY_DIR/start-server.sh" "$DEPLOY_DIR/install-service.sh" "$DEPLOY_DIR/update-if-requested.mjs" 2>/dev/null || true |
| 19 | |
| 20 | echo "[deploy] npm install…" |
| 21 | npm install --omit=dev |
| 22 | |
| 23 | echo "[deploy] Submodules…" |
| 24 | git submodule update --init --recursive |
| 25 | |
| 26 | echo "[deploy] Build client framework…" |
| 27 | npm run build:client |
| 28 | |
| 29 | if [[ ! -f client/frameworkv3/js/framework.js ]]; then |
| 30 | echo "[deploy] ERROR: client/frameworkv3/js/framework.js missing after build." >&2 |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | echo "[deploy] Starting server…" |
| 35 | exec node --experimental-sqlite server/src/index.js |