From 4cbcb4ddd52642a3dd50e272dbb22271ea9967e8 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 9 Dec 2025 21:59:02 +0100 Subject: [PATCH 1/4] Adapt UserService to trixie, make failure output work --- src/symbols/systemd/user_service.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/symbols/systemd/user_service.rs b/src/symbols/systemd/user_service.rs index fef5692..95af967 100644 --- a/src/symbols/systemd/user_service.rs +++ b/src/symbols/systemd/user_service.rs @@ -1,5 +1,5 @@ use crate::async_utils::sleep; -use crate::command_runner::{CommandRunner, SetuidCommandRunner}; +use crate::command_runner::{CommandRunner, StdCommandRunner, SetuidCommandRunner}; use crate::symbols::Symbol; use async_trait::async_trait; use std::error::Error; @@ -12,6 +12,7 @@ pub struct UserService<'a, S: AsRef, U: AsRef> { socket_path: S, service_name: &'a str, command_runner: SetuidCommandRunner, + root_command_runner: StdCommandRunner, } impl, U: AsRef> UserService<'static, S, U> { @@ -20,13 +21,14 @@ impl, U: AsRef> UserService<'static, S, U> { socket_path, service_name, command_runner: SetuidCommandRunner::new(user_name), + root_command_runner: StdCommandRunner, } } } impl, U: AsRef> UserService<'_, S, U> { async fn systemctl_wait_for_dbus(&self, args: &[&OsStr]) -> Result> { - let mut tries = 5; + let mut tries = 10; loop { let result = self.command_runner.run_with_args("systemctl", args).await?; if result.status.success() { @@ -34,14 +36,15 @@ impl, U: AsRef> UserService<'_, S, U> { } let raw_stderr = std::str::from_utf8(&result.stderr)?; let stderr = raw_stderr.trim_end(); - if stderr != "Failed to connect to bus: No such file or directory" { + if stderr != "Failed to connect to bus: No such file or directory" && + stderr != "Failed to connect to user scope bus via local transport: No such file or directory" { return Err(stderr.into()); } tries -= 1; if tries == 0 { return Err("Gave up waiting for dbus to appear".to_string().into()); } - sleep(Duration::from_millis(500)).await; + sleep(Duration::from_millis(100)).await; } } @@ -63,10 +66,10 @@ impl, U: AsRef> UserService<'_, S, U> { return Err( std::str::from_utf8( &self - .command_runner + .root_command_runner .get_output( "journalctl", - args!["--user", format!("--user-unit={}", self.service_name)], + args![ /*"--user", format!("--user-unit={}", self.service_name)*/ ], ) .await?, )? From b11742ffadf12ac6cf6d7533b48933dbf2c651f0 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 9 Dec 2025 21:59:38 +0100 Subject: [PATCH 2/4] Update nginx templates --- src/templates/nginx/mod.rs | 6 ++++-- src/templates/nginx/server.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/templates/nginx/mod.rs b/src/templates/nginx/mod.rs index aa2992d..8cbcc47 100644 --- a/src/templates/nginx/mod.rs +++ b/src/templates/nginx/mod.rs @@ -27,8 +27,10 @@ mod test { "/challenges_snippet.conf" ), "server { - listen 443 ssl http2; - listen [::]:443 ssl http2; + listen 443 ssl; + listen [::]:443 ssl; + http2 on; + server_name testdomain; include \"/challenges_snippet.conf\"; diff --git a/src/templates/nginx/server.rs b/src/templates/nginx/server.rs index 4e35b2d..cf90cf5 100644 --- a/src/templates/nginx/server.rs +++ b/src/templates/nginx/server.rs @@ -24,8 +24,10 @@ pub fn server_config, K: AsRef, T: Display, S: ) -> String { format!( "server {{ - listen 443 ssl http2; - listen [::]:443 ssl http2; + listen 443 ssl; + listen [::]:443 ssl; + http2 on; + server_name {}; include \"{}\"; From 36b85ff3507a3419f8a6ee92f5942cf558cd2c77 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 9 Dec 2025 21:59:48 +0100 Subject: [PATCH 3/4] Remove wrong must_use --- src/templates/nginx/server.rs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/templates/nginx/server.rs b/src/templates/nginx/server.rs index cf90cf5..e8ce780 100644 --- a/src/templates/nginx/server.rs +++ b/src/templates/nginx/server.rs @@ -92,12 +92,10 @@ pub trait SocketSpec { } impl> SocketSpec for T { - #[must_use] fn to_proxy_pass(&self) -> String { format!("unix:{}:", self.as_ref().to_str().unwrap()) } - #[must_use] fn to_uwsgi_pass(&self) -> String { format!("unix:{}", self.as_ref().to_str().unwrap()) } @@ -107,19 +105,16 @@ impl> SocketSpec for T { pub struct LocalTcpSocket(NonZeroUsize); impl LocalTcpSocket { - #[must_use] pub const fn new(x: NonZeroUsize) -> Self { Self(x) } } impl SocketSpec for LocalTcpSocket { - #[must_use] fn to_proxy_pass(&self) -> String { format!("localhost:{}", self.0) } - #[must_use] fn to_uwsgi_pass(&self) -> String { format!("localhost:{}", self.0) } From d363254f6e5e5e1dc4f660cbec873c94fb733ce7 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Tue, 9 Dec 2025 22:08:22 +0100 Subject: [PATCH 4/4] Use OsStr for systemd unit exec value --- src/builder.rs | 4 ++-- src/resources/mod.rs | 7 ++++--- src/templates/systemd.rs | 7 ++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index 5652a07..cefa680 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -456,11 +456,11 @@ impl> ImplementationBuilder> for De FileSymbol::new( conf_path.clone_rc(), if resource.4 { - systemd_nodejs_service(&resource.2, socket_path, &resource.3) + systemd_nodejs_service(resource.2.as_ref(), socket_path, &resource.3) } else { systemd_socket_service( socket_path, - resource.2.as_ref().to_str().unwrap(), + &resource.2, &resource.3, "", ) diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 06daa5f..9115201 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -5,6 +5,7 @@ use crate::artifacts::{ use crate::templates::php::FpmPoolConfig; use std::hash::Hash; use std::path::Path; +use std::ffi::OsStr; pub trait Resource { type Artifact; @@ -136,7 +137,7 @@ impl Resource for User { } #[derive(Debug, Hash, PartialEq, Eq)] -pub struct SystemdSocketService(pub D, pub &'static str, pub P, pub P, pub bool); +pub struct SystemdSocketService(pub D, pub &'static str, pub Rc, pub P, pub bool); impl Resource for SystemdSocketService { type Artifact = (PathArtifact, PathArtifact, UserNameArtifact); } @@ -179,7 +180,7 @@ impl Resource for ServePhp { // Domain, service name, exec, static, dir #[derive(Debug, Hash, PartialEq, Eq)] -pub struct ServeService(pub D, pub &'static str, pub P, pub P, pub P, pub bool); +pub struct ServeService(pub D, pub &'static str, pub Rc, pub P, pub P, pub bool); impl Resource for ServeService { type Artifact = PathArtifact; } @@ -187,7 +188,7 @@ impl ServeService> { pub fn new( domain: D, service_name: &'static str, - exec: impl Into>, + exec: impl Into>, static_path: impl Into>, working_directory: impl Into>, is_nodejs: bool, diff --git a/src/templates/systemd.rs b/src/templates/systemd.rs index 58f84da..4fb8aa1 100644 --- a/src/templates/systemd.rs +++ b/src/templates/systemd.rs @@ -1,8 +1,9 @@ use std::path::Path; +use std::ffi::OsStr; pub fn socket_service( socket_path: impl AsRef, - exec: &str, + exec: &OsStr, dir: impl AsRef, additional: &str, ) -> String { @@ -18,7 +19,7 @@ Restart=always WantedBy=default.target ", socket_path.as_ref().to_str().unwrap(), - exec, + exec.display(), dir.as_ref().to_str().unwrap(), additional ) @@ -31,7 +32,7 @@ pub fn nodejs_service, S: AsRef>( ) -> String { socket_service( &socket_path, - &format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()), + format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()).as_ref(), dir, &format!( "Environment=NODE_ENV=production