upgrade.sh's old -f/-w/-s flags let you skip a backup or the DB
migration independently of each other, with nothing to stop a
combination that didn't actually make sense for the change being
shipped. Replace them with two named modes:
- migrate: for a change that touches the DB. Full SQL+WAR+logs
backup, both the existing short-lived tier and a new, never-pruned
backup/migrations/<tag>/ tier (before/after snapshot plus the full
DB migration transcript, tee'd from manager-exec.sh). The tag comes
from build.xml's migrate(@host) target: the git version already
embedded in sportrum.war's WEB-INF/VERSION (see README for the
webapp project's own build.xml snippet this needs), plus an
optional interactive label via Ant's <input> task.
- hotfix-code: for a Java/resource change with no DB migration. WAR
backup only (no SQL dump, no indefinite copy), no manager-exec.sh
at all. Only reached after check-schema-diff.sh - a new script that
runs ICPManager's diff-meta against a staged, not-yet-installed
copy of manager.zip, entirely independent of the live webapp/Tomcat
- has already confirmed there's no pending schema change, hard
gating build.xml's hotfix-code(@host) target before Tomcat is ever
touched.
A third scenario (template-only hotfix, no Tomcat restart at all) is
intentionally not implemented yet - which files count as "templates"
and how they'd sync into the live webapp directory is still an open
question.
Dropped without replacement: the old storeonly (-s) mode and the
"leave Tomcat stopped" action argument - undocumented, flag-only
behaviors nothing here exercised, easy to reintroduce as an explicit
mode later if actually needed.
Also fixes a real gap found while testing this: a failed migration
left upgrade-cmds.sh exiting 0, which would have made upgrade.sh (and
an Ant sshexec with failonerror) report success on a failed DB
migration. And build.xml's deploy.key.passphrase had no default,
which (confirmed by testing) left the literal string
"${deploy.key.passphrase}" as the passphrase for anyone not setting
it in build.local.properties.
Verified with a full fake fixture (fake pg_dump, fake manager.zip/
manager-exec.sh, fake sportrum.war): migrate success, migrate
collision-refusal on a reused tag, migrate failure preserving the
before-snapshot without pruning, hotfix-code skipping the SQL/DB
steps, and check-schema-diff.sh's three exit codes (clean/
differences/broken) all behave as designed. Ant-side tag assembly
(<input> skip-when-preset, blank-label fallback, unsafe-character
rejection) verified the same way.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
install-scripts(@host) syncs upgrade.sh/upgrade-cmds.sh/upgrade-funs.sh/
tomcat_ctl.sh/restart.sh to the server so it never runs a stale
hand-copied version; deploy(@host) runs that first, then sshexecs
upgrade.sh itself, then checks the site responds.
Reuses the sportrum webapp project's own account (sportrum@host:2222,
same key as its release-all target) rather than a separate dedicated
deploy user like xzpect-timer's xztimer - upgrade.sh needs real
privilege (Tomcat control, pg_dump, DB migrations via the container's
NOPASSWD sudo), so a second account would need the same rights anyway.
This project's build.xml never builds or uploads sportrum.war/
manager.zip itself; that's release-all's job in the webapp project -
this one only does the actual deploy once those are already staged.
Uses the -lib lib.build / checked-in jsch jar approach for the JSch
classpath gotcha, same as xzpect-timer, rather than the webapp
project's ant-classloadertask trick - that one's JDK-8-only, and this
build isn't guaranteed to run under the same JDK as the webapp's.
Verified end-to-end short of an actual server: ant -p and ant help
both hit the documented pre-flight failures correctly (missing key,
missing JSch on classpath) before -lib is added, succeed after; with
a real generated key, sshexec correctly gets past key-parsing and
attempts a real connection.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
Each upgrade already writes a SQL dump + webapp/WAR snapshot pair
under a shared timestamp for tactical rollback. Add automatic
pruning of pairs older than RETENTION_DAYS (14), run right after
manager-exec.sh upgrade succeeds so nothing is discarded if the
upgrade itself failed. Pruning works from the union of timestamps
across sql/webapp/logs so a partial pair (one artifact skipped via
-f/-w) is still cleaned up without erroring.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
Check interval now adapts to the last observed condition instead of a
fixed cron cadence: every 30 min while normal, every 10 once elevated
or critical, so cron only needs one entry at the fastest interval this
ever needs. Also bundles recent request count/rate/avg duration from
Tomcat's stdout log into the same check and MaintenanceLog entry, to
give the heap numbers traffic context rather than running as a
separate job.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
Follows nightly-storeall.sh's cron-driven, single-check-per-invocation
shape and logs via maintenance_log(). No longer forces storeall - that
stays a manual decision until real incident data is available to
calibrate a trigger. Every run logs old-gen occupancy plus Full/Young
GC numbers and a normal/elevated/critical condition label, building a
GC history dataset for whenever that calibration work resumes.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
nightly-storeall.sh no longer sleeps/retries internally - it's meant to
be invoked every 30 min from 21:00-06:00 by cron and does a single
check-and-maybe-act per run, so a missed/killed run just gets picked up
at the next tick instead of losing all progress. No forced fallback if
still busy at the 06:00 cutoff - that's handled manually for now.
Add maintenance_log() to upgrade-funs.sh: drops a MaintenanceLog XML file
per event into WEB-INF/storage/maintenance-log/ (atomic temp+rename) for
the webapp to pick up and route to sms/email/etc via its own machinery.
Fire-and-forget, matching the shape of MaintenanceLog.java.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
nightly-storeall.sh and the heap-pressure safety valve have genuinely
different schedules: the former should run once a night and is patient
(wait for quiet traffic, bounded retry), the latter needs to run every
10-15 minutes around the clock and is impatient (heap occupancy only
climbs while storeall is deferred, so it forces a run immediately with
no regard for traffic once critical). Cramming both into one script
meant they could only ever run on the same cadence.
nightly-storeall.sh: dropped heap_pressure_critical and
HEAP_FORCE_THRESHOLD_PCT entirely - it's now traffic-driven only.
emergency-storeall.sh: new script, just the heap check + immediate
storeall if critical, exits 0 doing nothing otherwise so it's cheap to
run on a tight cron schedule.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
Two fixes surfaced while adding append_stream_batch (live-stream chunk
ingest) as a sixth busy indicator, per a walkthrough of the log:
1. The request-completion log line doesn't always start at column 1.
Some handlers print an unterminated progress fragment right before it
with no newline in between ("- processed N chunkssportrum: 6: ..."),
so an anchored ^sportrum: regex missed 99.9% of append_stream_batch's
occurrences in testing, and ~2-4% of the original five handlers' too
(not enough to break their validation, but still wrong). Switched to
grep -oE pulling the timestamp+handler substring from anywhere on the
line instead of anchoring at the start.
2. Added ProductionCommand.append_stream_batch to BUSY_PATTERN - it's
the live camera/stream ingest pipeline, active independently of both
video production and race timing. Notably starts earlier than
anything else tracked: on the event's setup day, a full day before
the race itself.
Re-validated against real log excerpts with both fixes in place: nights
still read as exactly zero, and both a mid-stream-test-burst case and a
well-after-the-burst case resolve correctly.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
Adds the script that decides when it's safe to flush in-memory state via
the app's storeall command, so a nightly backup's freeze doesn't land on
top of live race/production traffic.
Busy signal is presence, within a trailing window, of any of five Tomcat
stdout log handlers (get_clipcast_screenplay/start_production/
update_production/finish_production/ESTPushServlet) - deliberately
excludes the idle-node polling handlers (peek_productions_queue_new,
request_batch, producer_log), which fire continuously regardless of
whether real work is happening. Validated the exact bash logic (not just
the concept) against excerpts of a real two-day event's production log:
zero false positives/negatives across quiet-night, pre-event, ramp-up,
and peak-racing cases at a 10-minute window.
Two escape hatches force the run regardless of traffic: a bounded retry
budget (default ~2h) and a JVM old-gen heap-pressure check via
supervisorctl+jstat, since storeall is the only thing that flushes state
to Postgres and the only thing that unblocks the registry's WeakHashMap
GC eviction for anything currently dirty - it can't be deferred forever.
Two things are still placeholders, not yet validated against the real
server: TOMCAT_LOG's actual path (depends on supervisord's
stdout_logfile setting) and HEAP_FORCE_THRESHOLD_PCT (needs a real jstat
baseline). Both are called out inline.
Scope is deliberately narrow: this script only decides when to call
storeall and calls it. Taking the actual pg_dump/webapp backup is a
separate step to chain after a successful run.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
runcmd was hardcoded to the storeall command/status-file pair. Generalizing
it now so finishcalls and dumpregistry (planned server-side additions) can
reuse the same commands.txt/status.<cmd>.$pid polling handshake instead of
needing near-duplicate copies of the function.
Signature changed from `runcmd <resultvar>` to `runcmd <resultvar> <command>
[args...]`; updated the two existing call sites (restart.sh, upgrade.sh)
accordingly. Behavior for storeall itself is unchanged - verified the
generated commands.txt line is byte-identical to before.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb
These are the scripts currently run by hand on the old EC2 server to do a
full upgrade (safe storeall handshake, backups, explode WAR, run the
manager schema-migration tool, restart Tomcat). Committed as-is for now to
review and refactor from, except tomcat_ctl.sh, which is already rewritten
to control Tomcat via the new Docker container's supervisord (through the
"service" shim) instead of the old host's /etc/init.d/tomcat8, since that
service doesn't exist there. Kept as a drop-in replacement: the "status"
output still contains both literal substrings upgrade.sh and restart.sh
each grep for, so neither caller needed to change yet.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tj4SF2BGFxgoRYrCAzNpDb