max / makenotwork
1 file changed,
+22 insertions,
-0 deletions
| @@ -63,6 +63,28 @@ async fn main() { | |||
| 63 | 63 | return; | |
| 64 | 64 | } | |
| 65 | 65 | ||
| 66 | + | // Config-only validation mode. Loads Config::from_env() with the process | |
| 67 | + | // environment and exits — no DB connection, no migrations, no socket bind — | |
| 68 | + | // so a required var missing on a target (e.g. CDN_BASE_URL) is caught | |
| 69 | + | // *before* a deploy swaps the `current` symlink and restarts into a crash | |
| 70 | + | // loop. Sando's pre-swap config-drift guard runs `MNW_CHECK_CONFIG=1 | |
| 71 | + | // <binary>` on the target with its env sourced; also handy by hand. Prints a | |
| 72 | + | // stable sentinel line so a caller can distinguish a genuine config error | |
| 73 | + | // (exit 1) from a binary too old to support this mode (which would ignore | |
| 74 | + | // the var and fall through to normal startup). | |
| 75 | + | if std::env::var("MNW_CHECK_CONFIG").is_ok() { | |
| 76 | + | match Config::from_env() { | |
| 77 | + | Ok(_) => { | |
| 78 | + | println!("MNW_CONFIG_CHECK: ok"); | |
| 79 | + | std::process::exit(0); | |
| 80 | + | } | |
| 81 | + | Err(e) => { | |
| 82 | + | eprintln!("MNW_CONFIG_CHECK: error: {e}"); | |
| 83 | + | std::process::exit(1); | |
| 84 | + | } | |
| 85 | + | } | |
| 86 | + | } | |
| 87 | + | ||
| 66 | 88 | let config = Config::from_env().expect("Failed to load configuration"); | |
| 67 | 89 | tracing::info!("Configuration loaded"); | |
| 68 | 90 |