Skip to content

What keeps gomoe.dev running

ops/aws-deploy/host.ts installs and starts the server host’s services on every deploy, so a rerun converges and a replaced host comes back the same. Terraform makes the alarms. This page lists both, and the backups. Once /agents/calls exists, each deploy also runs the calls firewall, LiveKit and Caddy on the calls interface. No apply writes it yet, so they are off.

Unit What it does
agents-api.service Runs node --env-file=/srv/agents/.env server/api.ts as the user agents, uid 1001, in /srv/agents. It restarts 3 seconds after it exits, and starts at boot.
agents-api-credentials.timer Hands the API its own IAM role’s credentials at boot and every hour, through ops/aws-deploy/api-credentials.ts.
agents-imds-block.service Keeps uid 1001, the API’s user, from the instance metadata, so the API has only its own role. It starts before the API and nginx.
agents-backup.timer Runs the nightly backup, ops/aws-deploy/backup.ts, at 07:30 UTC. A run missed while the host was down runs at the next boot.
agents-follow.timer Runs ops/aws-deploy/follow.ts 5 minutes after boot and then 2 minutes after each run ends. See Deploy a change.
nginx Listens on the people port, 8080, as the user agents. See How people and computers reach gomoe.dev.
Docker Compose Runs Electric and the forge, each with restart: unless-stopped.
The CloudWatch agent Sends memory, disk, swap, CPU and a count of each named process, the API, nginx, Docker, Electric and the forge, every 60 seconds.
The Watchtower agent Installed and enrolled by the State Manager association agents-watchtower-enroll, on every Linux instance SSM manages in the account, when it registers and every 30 minutes.

RDS rotates the database password every 7 days and keeps it in Secrets Manager. The API reads it again from AGENTS_DB_SECRET_ARN once Postgres refuses the old one. Electric connects as a role of its own, whose password never rotates, unless /agents/electric-as says master.

alarms.tf sends each alarm, and its return to OK, to the SNS topic agents-alarms, which emails the stack’s alarm_email. The subscription works only once its confirmation link has been opened.

Alarm Fires when
agents-app-unhealthy The load balancer has no healthy target.
agents-app-5xx The targets answer more than 20 5xx responses in 5 minutes.
agents-server-status The server host fails its status checks.
agents-db-cpu RDS’s CPU is over 85%.
agents-db-storage RDS has less than 2 GiB free.
agents-db-connections RDS holds more than 150 connections.
agents-server-memory The host uses more than 90% of its memory.
agents-server-disk-root The root disk is more than 85% full.
agents-server-disk-data /data is more than 85% full.
agents-watchtower-down watch.gomoe.dev/healthz stops answering, so Watchtower’s own emails can’t go out (watchtower.tf).
agents-watchtower-status The Watchtower collector’s instance fails its status checks (watchtower.tf).
agents-watchtower-coverage A running instance older than 15 minutes has not reported to Watchtower for 10 minutes, or the coverage Lambda published nothing (watchtower-coverage.tf).
agents-watchtower-collector-health The collector has not reported its own /healthz as answering for 5 minutes, missing reports included (module watchtower, health_alarm_actions in watchtower.tf).

Each alarm in alarms.tf is checked over 5-minute periods. Every alarm but agents-app-5xx also fires when its data stops coming, as when the host stops reporting. The dashboard agents-hosts graphs the CloudWatch agent’s measures. ops/aws-deploy/alarm-drill.ts makes each of the first six alarms fire once on its real threshold, on throwaway resources wherever the condition would take the live stack down, and removes them after.

AWS Budgets emails the watchtower_notify addresses when the month’s spend passes 80% and 100% of the monthly budget, 500 USD by default, and when the forecast passes 100% (budget.tf, module budget-alarm).

Watchtower’s collector runs on a host of its own at watch.gomoe.dev, so the server it watches can’t take it down. It emails the watchtower_notify list in gomoe.tfvars when a rule in watchtower-rules.yaml.tftpl fires.

  • app-down, when https://gomoe.dev/health fails 6 probes in a row, 3 minutes.
  • host-silent, when an instance in the group hosts, which holds all but the check fleet and the conformance hosts, stops reporting for 3 minutes.
  • disk-over-80 and memory-over-85.
  • container-restarting, when a container restarts more than twice in 10 minutes.
  • backup-older-than-30h, when the nightly backup’s last success is older than 30 hours.
  • computer-stuck-starting, when a computer has not started after 5 minutes, and computers-failing, when computers stopped on an error nobody asked for.
  • lease-release-stuck, when a leased computer is still being given back 10 minutes after it began.
  • deploy-failed, deploy-rollback-failed and follower-silent, once following is on. See Deploy a change.

The CloudWatch alarms stay until each Watchtower rule has been seen firing.

Copy Kept by
A pg_dump --format=custom of the record, backups/<date>/record.dump in the objects bucket The nightly backup
An archive of the forge’s data, backups/<date>/forge.tar.gz in the objects bucket, made with the forge’s container paused The nightly backup
RDS’s own backups, 7 days RDS
Daily snapshots of the data volume, which holds /data/agents-app and the forge’s and Electric’s files A daily snapshot, which backup.ts’s header names
Old versions of agents’ homes, sessions, sealed secrets and the package cache under orgs/ in the objects bucket, 30 days The bucket’s versioning

The forge file is not in the forge archive, so SSM keeps a copy at /agents/forge/config.

Two scripts restore. Neither restores a nightly backup into the live record or the live forge.

  • node ops/aws-deploy/restore-rehearsal.ts <YYYY-MM-DD>, run as root on the host in /srv/agents, restores that day’s dump into a scratch database on the live RDS instance. It prints the live and the restored row counts of nine tables, teams, people, accounts, instances, agents, tasks, leases, messages and events, then drops the scratch database. It unpacks the day’s forge archive and starts the forge’s image on it in a scratch container on the host, with no published port. It prints the live and the restored forge’s users and repo counts, and runs git fsck on each restored repo. The script checks no count against another, so a person reads them, and counts can differ by rows written since the dump.
  • node ops/aws-deploy/move-in.ts <id> [--replace], run as root on the host, restores a move between AWS accounts from move/<id>/ in the bucket: the record, the forge, the state folder’s keys and the computers’ homes. It refuses a record that holds a team unless --replace is given.

No script restores RDS to a point in time or brings the data volume back from a snapshot.