Eight cron monitors, two per game, watched eight scripts that run on the same box at the same two minutes. hall-nightly.sh now runs the hall's own rollup and every game's rollup at 00:12, and every game's backup at 07:23, finding the games by their scripts in /usr/local/bin, and checks in once for each job to the gamehall project's hall-rollup and hall-backup monitors. The template's rollup and backup say by their exit status whether they managed, the skipped backup included, and its deploy leaves the game's own cron file off a host the hall schedules. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
70 lines
3.3 KiB
Bash
Executable File
70 lines
3.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build locally, push the static site and the game server to the droplet,
|
|
# and restart the server. Usage: deploy/deploy.sh <droplet-ip-or-host>
|
|
set -euo pipefail
|
|
HOST="${1:?usage: deploy.sh <droplet-ip-or-host>}"
|
|
|
|
# The family list is the kit's; a game deploys with the kit's latest copy when the kit is beside it.
|
|
KIT_FAMILY="$(dirname "$0")/../../game-kit/family.json"
|
|
[ -f "$KIT_FAMILY" ] && cp "$KIT_FAMILY" static/family.json
|
|
|
|
npm run check
|
|
npm run check:server
|
|
npm test
|
|
npm run build
|
|
|
|
# Every production ledger must replay identically with the engine about to ship.
|
|
deploy/verify-ledgers.sh "$HOST"
|
|
|
|
# Old hashed chunks stay a week: a page loaded before this deploy can still
|
|
# fetch the module it was built against instead of failing mid-game.
|
|
rsync -az --delete --filter='P _app/immutable/*' \
|
|
build/ "root@$HOST:/opt/__SLUG__/build/"
|
|
|
|
# The server runs from source with tsx and carries its own small manifest;
|
|
# it needs only its code and the engine. Ledgers live outside this tree.
|
|
rsync -az --delete --exclude='/server/node_modules' \
|
|
--include='/server/***' --include='/src/' --include='/src/lib/' --include='/src/lib/game/***' --include='/src/lib/net/' --include='/src/lib/net/view.ts' \
|
|
--include='/deploy/' --include='/deploy/__SLUG__.service' --include='/deploy/__SLUG__.cron' --include='/deploy/*.sh' --include='/deploy/traffic.py' \
|
|
--exclude='*' \
|
|
./ "root@$HOST:/opt/__SLUG__/app/"
|
|
|
|
ssh "root@$HOST" '
|
|
find /opt/__SLUG__/build/_app/immutable -type f -mtime +7 -delete
|
|
chown -R root:caddy /opt/__SLUG__/build
|
|
chmod -R g+rX /opt/__SLUG__/build
|
|
cd /opt/__SLUG__/app/server && npm install --no-audit --no-fund
|
|
chown -R __SLUG__:__SLUG__ /opt/__SLUG__/app
|
|
cp /opt/__SLUG__/app/deploy/__SLUG__.service /etc/systemd/system/__SLUG__.service
|
|
# The ops scripts run from /usr/local/bin and share traffic.py: install them
|
|
# on every deploy so the live copies are always the repo copies.
|
|
install -m 755 /opt/__SLUG__/app/deploy/__SLUG__-visitors.sh /usr/local/bin/__SLUG__-visitors.sh
|
|
install -m 755 /opt/__SLUG__/app/deploy/__SLUG__-pulse.sh /usr/local/bin/__SLUG__-pulse.sh
|
|
install -m 755 /opt/__SLUG__/app/deploy/__SLUG__-rollup.sh /usr/local/bin/__SLUG__-rollup.sh
|
|
install -m 755 /opt/__SLUG__/app/deploy/__SLUG__-backup.sh /usr/local/bin/__SLUG__-backup.sh
|
|
install -m 644 -D /opt/__SLUG__/app/deploy/traffic.py /usr/local/lib/__SLUG__/traffic.py
|
|
# On a host the hall shares, its hall-nightly.sh runs the rollup and backup
|
|
# of every game and checks in with Sentry once for all; a game on a box of
|
|
# its own schedules its own.
|
|
if [ -f /etc/cron.d/gamehall ]; then rm -f /etc/cron.d/__SLUG__
|
|
else install -m 644 /opt/__SLUG__/app/deploy/__SLUG__.cron /etc/cron.d/__SLUG__; fi
|
|
mkdir -p /var/log/__SLUG__
|
|
systemctl daemon-reload
|
|
systemctl enable --now __SLUG__
|
|
systemctl restart __SLUG__
|
|
systemctl reload caddy
|
|
# "active" means only that the process started: wait for it to answer HTTP,
|
|
# so a server that dies loading its code fails the deploy instead of looping.
|
|
for i in $(seq 20); do
|
|
if curl -s -o /dev/null http://127.0.0.1:__PORT__/api/rooms/ZZZZ; then
|
|
systemctl --no-pager -l status __SLUG__ | head -3
|
|
exit 0
|
|
fi
|
|
sleep 1
|
|
done
|
|
echo "the game server is not answering:" >&2
|
|
journalctl -u __SLUG__ -n 25 --no-pager >&2
|
|
exit 1
|
|
'
|
|
echo "deployed."
|