#!/usr/bin/env bash # Manage the on-demand staging instance. # ./deploy/staging.sh start # refresh DB from prod, start units # ./deploy/staging.sh stop # stop units # ./deploy/staging.sh status # show unit + URL status set -euo pipefail VPS="lichen" ACTION="${1:-}" case "$ACTION" in start) ssh "$VPS" " set -e sudo cp /var/lib/lichen/lichen.db /var/lib/lichen-staging/lichen.db sudo chown lichen:lichen /var/lib/lichen-staging/lichen.db sudo systemctl start lichen-appview-staging lichen-firehose-staging " sleep 3 STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 https://staging.lichen.wiki/) if [ "$STATUS" = "200" ]; then echo "Staging up: https://staging.lichen.wiki/ (HTTP $STATUS)" else echo "Staging started but health check returned HTTP $STATUS — check journalctl" exit 1 fi ;; stop) ssh "$VPS" "sudo systemctl stop lichen-appview-staging lichen-firehose-staging" echo "Staging stopped." ;; status) ssh "$VPS" "sudo systemctl is-active lichen-appview-staging lichen-firehose-staging || true" STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 5 https://staging.lichen.wiki/ || echo "down") echo "https://staging.lichen.wiki/ → HTTP $STATUS" ;; *) echo "Usage: $0 {start|stop|status}" >&2 exit 1 ;; esac