Skip to content

Plan + code to shut down the dfc server (move Vault, Redash, state DB, DNS to dfc2), no-op until switched on - #28

Draft
atalyaalon wants to merge 3 commits into
mainfrom
claude/laughing-galileo-165xk1-shutdown-dfc
Draft

atalyaalon wants to merge 3 commits into
mainfrom
claude/laughing-galileo-165xk1-shutdown-dfc

Conversation

@atalyaalon

@atalyaalon atalyaalon commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

🟢 Production impact

  • Opening, pushing or reviewing this PR: none. The only workflow it triggers is the read-only terraform plan. Its plan showed no DNS or Cloudflare changes from this PR. The plan does list 3 DKIM record updates, which are unrelated drift; see Before any terraform apply.
  • Merging to main: redeploys dfc2's anyway app (apps-dfc2/anyway changed) with 3 extra hostnames: airflow, airflow-data and reports.anyway.co.il.
    • That briefly restarts airflow-nginx, airflow-webserver and reports on dfc2.
    • Traefik starts failing certificate requests for those names until DNS moves, which is harmless.
    • It also writes back whatever backup schedule main has at that time (see #24).
    • Nothing else gets deployed: the copied apps are never deployed automatically.
  • terraform apply after merging: adds read access to the dfc2-anyway-partial-db-dumps bucket for the dev reader user. Nothing else from this PR, because all the switches are off.
  • ⚠️ Any untargeted terraform apply from this repo also applies the other pending changes and reverts manual AWS changes. See Before any terraform apply.

💰 Estimated saving: ~$140/month, once the whole runbook is done

~$76 instance (m6a.large) + ~$57 disks (600 GB gp3) + ~$4 Elastic IP + its monthly snapshots (eu-central-1 list prices, approximate).

Related PRs

# PR What
0 dfc-iac#27 Deploy only from main. Urgent.
1 anyway#2965 Local restore uses the latest complete dump
2 dfc-iac#24 Monthly backups, clean-up, 1-year expiry
3 dfc-iac#25 Free monitoring; Tamar's measurements (they cover dfc too)
4 This PR Shut down dfc: code + runbook, all switched off
5 dfc-iac#26 dfc2 instance type: better sized after this, since dfc2 takes over dfc's services
6 dfc-iac#29 Smaller dfc2 data disk: also after this

Stacked on #25 (base claude/laughing-galileo-165xk1-monitoring), so this diff shows only this PR's changes.

What's in it

1. Runbook: docs/DECOMMISSION_DFC.md (start here)

  • Rules for every step:

    • never an untargeted terraform apply; only the exact -targets given
    • copy files only with plain ssh helpers and sha256sum checks
    • one service at a time
  • Phase 0: checks only.

    • Is dfc's anyway stack really unused (DAGs, double-posting)?
    • Who connects to dfc's DBs? Checked with pg_stat_activity.
    • Is there room on dfc2?
    • The security group, the VAULT_ADDR GitHub secret, the backend sslmode, the names on dfc's * wildcard, and the Docker version.
    • Snapshots, and a Terraform freeze.
  • Phase 1: move the services, one at a time, in this order:

    1. Terraform state DB, first, while Vault is still up
    2. Redash, with its data source switched to dfc2's DB over the internal docker network
    3. the anyway hostnames: airflow, airflow-data, reports, oway, ws
    4. Vault, last. All CI and deploys are down for ~15–30 minutes.

    After each DNS switch: restart traefik and check the certificate. Each step includes its checks and a rollback.

  • Phase 2: stop dfc's anyway stack and move its cron files away. Reversible.

  • Phase 3: code clean-up: workflows, apps/, and the anyway repo's dump bucket.

  • Phase 4: delete dfc with Terraform. ⚠️ dfc2 may share the VPC and security group that module.dfc creates, and the * wildcard goes away. Both must be handled first; the runbook has the exact checks.

2. On/off switches: modules.tf

  • A moved_to_dfc2 map with one switch per service, all false:
    • redash and vault: Cloudflare CNAMEs that override dfc's * wildcard
    • airflow, reports, ws and oway: the Route53 records in modules/anyway/dns.tf
  • Each runbook step flips its switches in its own small PR, and applies only the exact records with -target.

3. Apps copied to dfc2: apps-dfc2/vault, apps-dfc2/redash, apps-dfc2/cluster-admin

  • They're copies of apps/…, marked x-skip-deploy-all: true.
  • bin/apps-dfc2.py deploy_all_apps now skips them, so they can never start by accident with an empty data folder. They're deployed only one by one, with deploy_app, after their data is copied. I tested this: deploy_all_apps would deploy only anyway, selenium and traefik.

4. dfc2 answers the remaining hostnames

  • apps-dfc2/anyway/compose.yaml: the airflow, airflow-data and reports routers also accept the *.anyway.co.il names.
  • apps-dfc2/traefik: a new oway_redirects.yaml redirects oway.org.il and www.oway.org.il to anyway.co.il.

5. Developer dump access

partial_db_dumps_reader can also read dfc2-anyway-partial-db-dumps. That's needed when developers switch to dfc2's dumps in Phase 3.

Before any terraform apply

The read-only terraform plan shows manual AWS changes that an apply would undo. This isn't caused by this PR: the same happens when applying #24, #25 or #26.

  • Ziv's access: dfc2-anyway-db-dumps-reader got read access to the dfc-anyway-cbs bucket, plus a tag "Ziv keys to create local db volume", by hand. An apply removes both.
  • 3 DKIM email records (*._domainkey.anyway.co.il): an apply rewrites them with a trailing dot and TTL 1800 → 300. Probably harmless.
  • Fix before anyone applies: add Ziv's bucket access (and the tag, if wanted) to modules/anyway/aws_db_dumps_users.tf.

Review

Reviewed by a separate agent, read-only. Code: ready. The production impact claims: accurate (wording corrected above).

Runbook findings, all fixed:

  • The DNS step used -target=module.anyway, which would also have applied Reduce DB backup costs: monthly dumps + expire dumps older than 1 year #24's dump deletion and Free uptime + DB backup monitoring, remove paid Route53 health checks #25's health check removal, and undone Ziv's access. It now targets the exact records.
  • bin/apps*.py ssh runs ssh -t and prints OK, which corrupts copied files (dumps, Vault data, unseal keys). The runbook now uses plain ssh helpers and sha256sum checks.
  • Redash: "stop, then dump" stopped its own Postgres. It now stops only the app containers. Its data source now goes over the internal docker network.
  • Traefik doesn't retry a failed certificate by itself, so the runbook now restarts it and checks the certificate after each DNS switch.
  • Added: checks for the VAULT_ADDR secret, the backend sslmode, the wildcard names and the Docker version; the Terraform freeze and pg_isready; pg_stat_activity instead of ss; moving dfc's cron files away in Phase 2; tar --numeric-owner; dump clean-up on both servers.

Conditions to merge

Testing

🤖 Generated with Claude Code

https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV

@atalyaalon
atalyaalon requested review from tkalir and ziv17 November 29, 2026 01:26
atalyaalon pushed a commit that referenced this pull request Nov 30, 2026
…ounted check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
@atalyaalon
atalyaalon force-pushed the claude/laughing-galileo-165xk1-shutdown-dfc branch from ab3d5c7 to 580be61 Compare November 30, 2026 00:35
@atalyaalon
atalyaalon added this pull request to stack #31 November 30, 2026 01:00
Base automatically changed from claude/laughing-galileo-165xk1-monitoring to main November 30, 2026 01:31
…lip)

- copy apps/vault, apps/redash, apps/cluster-admin to apps-dfc2, marked
  x-skip-deploy-all so deploy_all_apps never starts them with empty data
- dfc2 traefik: oway.org.il redirect; dfc2 anyway: also answer
  airflow, airflow-data and reports .anyway.co.il
- Terraform: per-service moved_to_dfc2 flags in modules.tf (all false,
  so no change) switching the Route53 records and adding Cloudflare
  CNAMEs for vault/redash on dfc2
- dev partial dumps reader can also read the dfc2 partial bucket
- docs/DECOMMISSION_DFC.md: step-by-step runbook, checks, rollbacks

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
- exact -target addresses for the DNS step (never -target=module.anyway,
  which would also apply unrelated pending changes)
- copy files with plain ssh helpers and sha256sum checks: bin/apps*.py
  ssh uses -t and prints OK, which corrupts copied files
- Redash: keep its Postgres running for the dump; data source via the
  internal docker network
- restart traefik and check the certificate after each DNS switch
- Phase 0: VAULT_ADDR secret, backend sslmode, wildcard names, Docker
  version, Terraform freeze; pg_stat_activity instead of ss
- state DB: stop the old DB right after the dump, wait for pg_isready
- Phase 2: move dfc's anyway cron files away; expect backup alerts
- tar --numeric-owner, clean up dumps on both servers, typo

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV
- bin/apps-dfc2.py: strip \r from server: secrets (read through ssh -t),
  which corrupted multi-line values like the Vault unseal keys
- runbook: moving the shared VPC and security group out of module.dfc
  is required (confirmed same IDs), not conditional
- flag that the shared security group exposes 9001/9002 to the internet
- do #26/#29 before Phase 1 or after the move (dfc2 restarts would take
  down Terraform's own backend), don't restart traefik repeatedly
- manual unseal fallback; re-run deploys that failed while Vault moved

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XtN7GhfRRihvBTHsWxGZoV

Copy link
Copy Markdown
Contributor Author

@tkalir @ziv17, a question before this PR moves DNS and shuts down the dfc server: which hostnames, and which server, do we want to keep? It also decides which database the PostgreSQL 18 upgrade (data-for-change/anyway#2964) migrates, and how much space dfc2 needs before #29 shrinks /data.

Today, from main (d738dcc)

Hostname Served by
anyway.co.il (apex), plus www.anyway.co.il → redirect to the apex (b144ce7, 6 Nov; #33 now serves API and login paths on www directly) dfc2
safety-data.anyway.co.il dfc2
airflow.anyway.co.il, airflow-data.anyway.co.il, reports.anyway.co.il, ws.anyway.co.il old dfc
www.dfc2., airflow.dfc2., airflow-data.dfc2., reports.dfc2., safety-data.dfc2.anyway.co.il dfc2

Each server runs its own Airflow, ETL and DB. The public site reads dfc2's DB, while airflow.anyway.co.il still points at the old dfc server's Airflow, which writes to its own DB. This PR adds airflow, airflow-data and reports.anyway.co.il as extra names on dfc2.

Questions

  1. Long-term names: do we keep the original names (anyway.co.il, airflow.anyway.co.il, reports.anyway.co.il…) and drop the *.dfc2.anyway.co.il ones? The other way round? Or both, as aliases? And is the apex anyway.co.il the canonical site address? Allow https://anyway.co.il in CORS and post-login redirects anyway#2966 assumes it is.
  2. Which DB is authoritative now: is dfc2's DB the real production data? Does anything still use the old dfc server's DB or its Airflow: Redash, ETL alerts, people working in airflow.anyway.co.il?
  3. Old dfc DB: if it's no longer needed, the PG 18 migration would be done only on dfc2, and this PR would shut down the old server without migrating its DB. Does that sound right?

Suggested order, if you agree

  1. Wait for and check the 1 Dec monthly backup.
  2. Do the PG 18 migration on dfc2 (anyway#2964 runbook).
  3. Do Plan + code to shut down the dfc server (move Vault, Redash, state DB, DNS to dfc2), no-op until switched on #28 (this PR).
  4. Do dfc2: prepare moving /data to a smaller disk (500 GB → ~250 GB), no-op until the size is set #29 (smaller disk), then dfc2: move to a cheaper instance type (m6a.large → t3a.large), only once the measurements allow it #26 (instance type).

#29 should come after PG 18, because the migration needs room for the old and new data directories plus a dump at the same time. It should also come after this PR, because this PR adds Vault, Redash and the state DB data to dfc2's /data.

Same question on the PG 18 PR: data-for-change/anyway#2964 (comment)


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants