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/activity.rs b/server/src/activity.rs index d6f1256..76607b8 100644 --- a/server/src/activity.rs +++ b/server/src/activity.rs @@ -166,7 +166,7 @@ fn describe(method: &Method, path: &str) -> Option { ("POST", "/settings/notify", "Change notifications"), ("POST", "/settings/model", "Change the agent's model"), ("POST", "/settings/memory", "Change the memory reserve"), - ("POST", "/domains/*/env", "Change environment variables"), + ("POST", "/domains/*/env", "Change and apply app env"), ("POST", "/groups/*/workers", "Add worker"), ("POST", "/workers/*", "Change worker"), ("DELETE", "/workers/*", "Delete worker"), 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..afef92c 100644 --- a/webui/src/components/AppEnv.svelte +++ b/webui/src/components/AppEnv.svelte @@ -1,5 +1,5 @@