This commit is contained in:
Mateusz Gruszczyński committed 2026-11-21 14:03:29 +01:00
1 parent 3b5fc8dce1
commit 748fe1d146
23 files changed
+2901 -40

No files matched your search

+76 -13
View File
@@ -11,16 +11,21 @@ async fn run(
startup_admin_addr.port() > 0 && options.proxy_listen.port() > 0,
"listener ports must be nonzero"
);
let headless_options = options.headless_tls.clone().resolve(headless)?;
if headless {
ensure!(
file_config.is_some(),
"--headless requires --config /absolute/path/config.json (or RUST_PROXY_CONFIG)"
file_config.is_some() || !headless_options.routes.is_empty(),
"--headless requires --config /absolute/path/config.json (or RUST_PROXY_CONFIG) or at least one --route HOST=URL"
);
ensure!(!options.demo, "--headless cannot be combined with --demo");
rust_proxy::runtime::enable_headless(rust_proxy::settings::Listeners::from_startup(
options.proxy_listen,
options.tls_listen,
));
rust_proxy::runtime::configure_headless_options(
headless_options.clone(),
data_dir.join("certs"),
);
}
if let Some(health) = options.health_listen {
ensure!(
@@ -97,16 +102,24 @@ async fn run(
};
let store = Store::open(&data_dir.join("config.sqlite3"), &initial).await?;
let mut saved = store.load().await?;
let external = if let Some(path) = file_config {
let loaded = match rust_proxy::runtime::headless_listeners() {
Some(listeners) => {
rust_proxy::runtime::external_config::read_headless(&path, listeners)?
}
None => rust_proxy::runtime::external_config::read(&path)?,
};
Some((path.clone(), loaded))
} else {
None
let mut headless_load = None;
let external = match rust_proxy::runtime::headless_listeners() {
Some(listeners) => {
let load = rust_proxy::runtime::external_config::load_headless(
file_config.as_deref(),
listeners,
)?;
let loaded = (load.config.clone(), load.fingerprint);
headless_load = Some((load.tls, load.watch, load.added_certificates));
Some((file_config.clone(), loaded))
}
None => match file_config {
Some(path) => Some((
Some(path.clone()),
rust_proxy::runtime::external_config::read(&path)?,
)),
None => None,
},
};
let saved_revision = saved.revision;
let stored_document = serde_json::to_value(&saved.config)?;
@@ -229,9 +242,17 @@ async fn run(
startup_locks,
geoip,
);
if let Some((path, (_, hash))) = external {
if let Some((Some(path), (_, hash))) = external {
state.set_config_file(path, hash).await;
}
let headless_watch = headless_load.as_ref().is_some_and(|(_, watch, _)| *watch);
let headless_tls = headless_load
.as_ref()
.map(|(tls, _, _)| tls.clone())
.unwrap_or_default();
if let Some((tls, watch, _)) = headless_load.clone() {
rust_proxy::runtime::publish_headless_tls(tls, watch);
}
state
.prometheus_token_hash
.store(store.prometheus_token_hash().await?.map(Arc::new));
@@ -401,6 +422,16 @@ async fn run(
};
if headless {
tasks.spawn(headless_reload_loop(state.clone(), shutdown.clone()));
// Both tasks follow reloads: ACME settings or watch targets may change.
state.tunnels.spawn(rust_proxy::acme::headless_loop(
Arc::downgrade(&state),
state.shutdown.clone(),
));
if headless_watch {
state
.tunnels
.spawn(headless_watch_loop(state.clone(), shutdown.clone()));
}
}
if let Some(admin_listener) = admin_listener {
if let Some(tls) = admin_tls_config {
@@ -484,11 +515,43 @@ async fn run(
.map(|(path, _)| path.clone())
{
println!(" Mode: headless, configuration {}", path.display());
} else {
println!(
" Mode: headless, {} route(s) from the command line",
headless_options.routes.len()
);
}
if headless_watch {
println!(" Watch: configuration and certificate files are reloaded on change");
}
println!(
" Reload: systemctl reload rustproxy, kill -HUP {}, or rust-proxy --headless reload",
std::process::id()
);
if let Some((_, _, added)) = &headless_load {
if *added > 0 || headless_tls.acme.is_some() {
println!(" TLS: {added} certificate(s) from headless TLS sources");
}
}
if !headless_tls.is_empty() {
let tls_listener = state.active_listeners.iter().any(|listener| listener.tls);
if !tls_listener {
tracing::warn!("headless TLS certificates are configured but no HTTPS listener is active; add --tls-listen 0.0.0.0:443 (or an https listener in the file)");
}
if let Some(acme) = &headless_tls.acme {
println!(
" ACME: {} certificate(s){}, {} via {}; state in {}",
acme.certificates.len(),
if acme.auto { " + automatic for vhost hosts" } else { "" },
acme.environment,
acme.provider,
data_dir.join("certs").join(rust_proxy::runtime::HEADLESS_ACME_STATE).display()
);
if acme.provider == "http01" && !state.active_listeners.iter().any(|listener| !listener.tls) {
tracing::warn!("ACME HTTP-01 needs a plain HTTP listener reachable on port 80");
}
}
}
} else {
println!(
" Panel: {}://{admin_addr}",