#!/usr/bin/env bash # The move: handover --move runs this on the VM once Railway's app services # are stopped and the last copy of the data is here. # From https://exe.dev/deploy/migrate-railway # # railway/move restore the data, start everything, turn cron jobs on # railway/move undo turn cron jobs off and say how to restart Railway set -euo pipefail cd ~/app log() { printf '\033[1m%s\033[0m\n' "$*"; } mapfile -t stopped < <(~/railway/import plan | awk -F'\t' '$1 == "stop" {print $2}') if [ "${1:-}" = undo ]; then crontab ~/app/crontab.base log "Cron jobs are off on the VM. To bring Railway back, on your computer:" for s in "${stopped[@]}"; do echo " railway redeploy --service '$s' --from-source --yes"; done exit fi railway=$(cat ~/railway/railway-url) code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 20 "$railway/" || true) case $code in 2*|3*) log "Railway still answers at $railway ($code). Stop it first: handover --move does."; exit 1 ;; esac log "Stopping the app on the VM, restoring the last copy of the data" mapfile -t apps < <(~/railway/import list | awk -F'\t' '$3 == "code" || $3 == "image" {print $2}') docker compose stop "${apps[@]}" ~/railway/restore log "Starting everything" docker compose up -d cat ~/app/crontab.base ~/app/crontab.jobs | crontab - sleep 10 docker compose ps --format 'table {{.Service}}\t{{.Status}}' log "Comparing pages with Railway's answers from the rehearsal" ~/railway/check --saved || log "Some pages differ: look before you change DNS." date -u +%FT%TZ > ~/railway/moved cat < ssh exe.dev share set-public $(hostname) Changed your mind? ssh $(hostname).exe.xyz railway/move undo NEXT