From 94c4433fc87452a6ea65d04e7306321a113bac4e Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 14 Nov 2026 06:19:00 +0100 Subject: [PATCH 1/2] Apply an app's environment variables when they are saved The panel stored a new variable but the app only got it with the next apply: on gs2 the operator added CHOCHBUECH_ANTHROPIC_KEY and the app ran without it until genco's agent applied hours later. Saving now runs apply, which writes the env file and restarts the app; an apply error shows beside the form. Co-Authored-By: Claude Opus 5.5 --- docs/OPERATIONS.md | 2 +- server/src/appenv.rs | 27 +++++++++++++++++++++------ webui/src/components/AppEnv.svelte | 16 ++++++++++++---- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/docs/OPERATIONS.md b/docs/OPERATIONS.md index 50ecde0..2e4dcfd 100644 --- a/docs/OPERATIONS.md +++ b/docs/OPERATIONS.md @@ -119,7 +119,7 @@ into the server's config, and the CLI does the same: | A server without mail (port 25 blocked, no relay) | Settings → Mail → No mail: deletions are confirmed in the panel with the 2FA code (the password without 2FA), no invites, no new mail domains, reports only in the panel and webhooks | | genco sends mail but hosts none | Settings → Mail → uncheck Mail hosting: no new mail domains, mailboxes, forwards or send-only addresses (panel, CLI and agent refuse them); genco's own mails (confirmations, invites, proposal links) keep going. Existing mail domains stay and keep running until deleted; without any, Dovecot, Rspamd and the submission ports stay off as always. No mail implies hosting off | | A PostgreSQL database | `genco database add --group --postgres`, then `genco apply` (installs PostgreSQL the first time) | -| Environment variables of an app | `genco domain env --set NAME=value --secret NAME=value --unset NAME`, then `genco apply` | +| Environment variables of an app | The domain's page (saving applies and restarts the app), or `genco domain env --set NAME=value --secret NAME=value --unset NAME`, then `genco apply` | | A stored password (Start → Passwords) | `genco secret list`, `genco secret show ` | | Block an address or range from the sites and mail (never ssh) | `genco firewall block 203.0.113.7 [--for 24h] [--note "..."]`, `genco firewall unblock `, `genco firewall list`; Settings → Firewall (see below) | | Reset an admin's password | `genco user password ` (reads the password from stdin) | diff --git a/server/src/appenv.rs b/server/src/appenv.rs index 00ad955..7c14710 100644 --- a/server/src/appenv.rs +++ b/server/src/appenv.rs @@ -2,6 +2,10 @@ //! domain, written to a file only root reads, which the app's unit loads //! (`EnvironmentFile`, systemd reads it before it drops to the group's //! user). Secret values never go back to the browser or the terminal. +//! Saving in the panel applies at once: the file is written and the app +//! restarts with the new variables. + +use std::sync::Arc; use axum::extract::{Path, State}; use axum::routing::get; @@ -10,6 +14,8 @@ use rusqlite::{Connection, params}; use serde::{Deserialize, Serialize}; use crate::AppState; +use crate::apply; +use crate::config::Config; use crate::db::Db; use crate::error::{Error, Result}; use crate::events::{Event, Events}; @@ -177,15 +183,26 @@ struct EnvRow { from: Option, } +/// Stores the variables and applies: the app restarts with them. async fn set_env( _authed: Authed, + State(cfg): State>, State(db): State, State(events): State, Path(id): Path, Json(rows): Json>, -) -> Result> { - let conn = db.conn(); - let old = load(&conn, id)?; +) -> Result> { + // the connection mustn't be held over the apply + store(&db.conn(), id, rows)?; + let report = apply::apply(&cfg, &db).await; + events.send(Event::Tree); + Ok(Json(report)) +} + +/// The panel's rows as the domain's variables; an empty value keeps a +/// secret's. +fn store(conn: &Connection, id: i64, rows: Vec) -> Result<()> { + let old = load(conn, id)?; let mut vars = vec![]; for r in rows { let was = r @@ -216,9 +233,7 @@ async fn set_env( "UPDATE domains SET env = ?1 WHERE id = ?2", params![serde_json::to_string(&vars).unwrap(), id], )?; - drop(conn); - events.send(Event::Tree); - Ok(Json(())) + Ok(()) } pub fn routes() -> Router { diff --git a/webui/src/components/AppEnv.svelte b/webui/src/components/AppEnv.svelte index eea1fbb..a0bee14 100644 --- a/webui/src/components/AppEnv.svelte +++ b/webui/src/components/AppEnv.svelte @@ -1,5 +1,5 @@