Files
crosscode-platform/scripts/lib/status.sh
T
joshuaandClaude Opus 5.5 c442fe0d42 crosscode script: deploy, status, install, adopt (Events 2.2.0, plan §4-5)
One script for installing, updating and moving church installs, replacing
hope-events' scripts/deploy.sh and install.sh:

- deploy <church> [events] / --every-church, with --version, --main, --check
  and --allow-local-changes: checks every product first (files changed by
  hand, Node, release requirements from WHATS-NEW.md headings), then each
  product in order with backup, checkout, install, migrate, build, PM2 reload
  and a /health version check; a failure rolls that product back and stops.
- status [<church>]: checked-out and latest release, /health, and the old
  folder kept after adopt.
- install <church> --products events --domain <address>: a new church under
  /var/www/sites/<church>, writing church.env.
- adopt <church> --events-dir <old> builds the monorepo checkout next to the
  running install and switches PM2 over; adopt --undo goes back to it.

Product hooks live in scripts/products/events.sh. shellcheck (lint:scripts)
and 47 bats tests (test:scripts) are part of npm run check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 19:17:06 +02:00

90 lines
3.2 KiB
Bash

# shellcheck shell=bash
# crosscode status [<church>]: each product's version, latest release, health and last backup.
status_usage() {
cat <<'EOF'
crosscode status [<church>] [--no-fetch]
Each product's checked-out release, the latest release, and what /health reports (version,
database, jobs, last backup), for one church or every church on this server.
--no-fetch don't fetch tags first (faster; "latest" may be out of date)
EOF
}
cmd_status() {
local church="" fetch=1
while [ $# -gt 0 ]; do
case "$1" in
--no-fetch) fetch=0; shift ;;
-h|--help) status_usage; return 0 ;;
-*) die "Unknown option $1 (crosscode status --help)." ;;
*) [ -z "$church" ] || die "One church at a time."; church="$1"; shift ;;
esac
done
require_root
local -a churches
if [ -n "$church" ]; then
churches=("$church")
else
mapfile -t churches < <(list_churches)
[ "${#churches[@]}" -gt 0 ] || { info "No churches on this server ($CROSSCODE_SITES/*/church.env)."; return 0; }
fi
local c
for c in "${churches[@]}"; do status_church "$c" "$fetch"; done
}
status_church() {
local church="$1" fetch="$2" p dir user ref latest url json version db jobs backup line
load_church "$church"
echo
step "$church ($(cenv ADDRESS '(no address)'))"
# shellcheck disable=SC2046 # PRODUCTS is a space-separated list of names
for p in $(in_product_order $(cenv PRODUCTS)); do
dir="$(pvar "$p" DIR)"
user="$(pvar "$p" USER)"
if [ ! -d "$dir/.git" ]; then
info "$(printf '%-9s %s' "$p" "missing checkout: $dir")"
continue
fi
if [ "$fetch" = 1 ]; then
run_as "$user" "$dir" timeout 20 git fetch --tags --quiet origin 2>/dev/null || true
fi
ref="$(checkout_ref "$dir" "$p")"
latest="$(latest_tag "$dir" "$p")"
line="$(printf '%-9s %-16s latest %-16s' "$p" "$ref" "${latest:-none}")"
[ -n "$latest" ] && [ "$ref" != "$latest" ] && line="$line (update available)"
info "$line"
if is_supported_product "$p"; then
# shellcheck source=/dev/null
source "$CROSSCODE_HOME/products/$p.sh"
url="$("${p}_health_url")"
if json="$(health_json "$url")"; then
version="$(printf '%s' "$json" | json_get version)"
db="$(printf '%s' "$json" | json_get db)"
jobs="$(printf '%s' "$json" | json_get jobs)"
backup="$(printf '%s' "$json" | json_get lastBackupAt)"
info " health: version ${version:-?}, database ${db:-?}, jobs ${jobs:-?}, last backup ${backup:-never}"
else
warn " $p isn't answering on $url (pm2 status; pm2 logs)."
fi
fi
status_old_folder "$p"
done
}
# After `adopt`, the old folder is kept for 14 days so `adopt --undo` can go back to it.
status_old_folder() {
local p="$1" old at age
old="$(pvar "$p" OLD_DIR)"
at="$(pvar "$p" ADOPTED_AT)"
[ -n "$old" ] && [ -d "$old" ] || return 0
age=$(( ($(date +%s) - $(date -d "$at" +%s 2>/dev/null || date +%s)) / 86400 ))
if [ "$age" -ge 14 ]; then
warn " The old folder $old is $age days old, past the 14 days kept for \`adopt --undo\`: remove it (rm -rf $old)."
else
info " Old folder kept for \`adopt --undo\`: $old (adopted $at, $((14 - age)) days left)."
fi
}