Apply environment variable overrides to a loaded `ServerConfig`. Priority order: env var > TOML value > compiled default. Handled variables: - `NODEDB_HOST` — overrides `config.host` (bind address, e.g., `0.0.0.0`) - `NODEDB_PORT_NATIVE` — overrides `config.ports.native` (default 6433) - `NODEDB_PORT_PGWIRE` — overrides `config.ports.pgwire` (default 6432) - `NODEDB_PORT_HT
(config: &mut ServerConfig)
| 164 | /// (called from `main.rs`) so that the value is never passed through logging |
| 165 | /// code paths or stored in `ServerConfig` where it could appear in debug output. |
| 166 | pub fn apply_env_overrides(config: &mut ServerConfig) { |
| 167 | // ── Host and ports ───────────────────────────────────────────── |
| 168 | |
| 169 | if let Ok(val) = std::env::var("NODEDB_HOST") { |
| 170 | match val.trim().parse::<IpAddr>() { |
| 171 | Ok(ip) => { |
| 172 | tracing::info!(env_var = "NODEDB_HOST", value = %val, "environment variable override applied"); |
| 173 | config.server.host = ip; |
| 174 | } |
| 175 | Err(_) => { |
| 176 | tracing::warn!( |
| 177 | env_var = "NODEDB_HOST", |
| 178 | value = %val, |
| 179 | "ignoring malformed environment variable (expected IP address), using config value" |
| 180 | ); |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | apply_port_env("NODEDB_PORT_NATIVE", &mut config.server.ports.native); |
| 186 | apply_port_env("NODEDB_PORT_PGWIRE", &mut config.server.ports.pgwire); |
| 187 | apply_port_env("NODEDB_PORT_HTTP", &mut config.server.ports.http); |
| 188 | apply_optional_port_env("NODEDB_PORT_RESP", &mut config.server.ports.resp); |
| 189 | apply_optional_port_env("NODEDB_PORT_ILP", &mut config.server.ports.ilp); |
| 190 | |
| 191 | if let Ok(val) = std::env::var("NODEDB_DATA_DIR") { |
| 192 | let path = std::path::PathBuf::from(&val); |
| 193 | tracing::info!( |
| 194 | env_var = "NODEDB_DATA_DIR", |
| 195 | value = %val, |
| 196 | "environment variable override applied" |
| 197 | ); |
| 198 | config.server.data_dir = path; |
| 199 | } |
| 200 | |
| 201 | if let Ok(val) = std::env::var("NODEDB_MEMORY_LIMIT") { |
| 202 | match parse_memory_size(&val) { |
| 203 | Ok(bytes) => { |
| 204 | tracing::info!( |
| 205 | env_var = "NODEDB_MEMORY_LIMIT", |
| 206 | value = %val, |
| 207 | bytes, |
| 208 | "environment variable override applied" |
| 209 | ); |
| 210 | config.server.memory_limit = bytes; |
| 211 | } |
| 212 | Err(e) => { |
| 213 | tracing::warn!( |
| 214 | env_var = "NODEDB_MEMORY_LIMIT", |
| 215 | value = %val, |
| 216 | error = %e, |
| 217 | "ignoring malformed environment variable, using config value" |
| 218 | ); |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | if let Ok(val) = std::env::var("NODEDB_NODE_ID") { |