diff --git a/src/builder.rs b/src/builder.rs index cefa680..5652a07 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.as_ref(), socket_path, &resource.3) + systemd_nodejs_service(&resource.2, socket_path, &resource.3) } else { systemd_socket_service( socket_path, - &resource.2, + resource.2.as_ref().to_str().unwrap(), &resource.3, "", ) diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 9115201..06daa5f 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -5,7 +5,6 @@ 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; @@ -137,7 +136,7 @@ impl Resource for User { } #[derive(Debug, Hash, PartialEq, Eq)] -pub struct SystemdSocketService(pub D, pub &'static str, pub Rc, pub P, pub bool); +pub struct SystemdSocketService(pub D, pub &'static str, pub P, pub P, pub bool); impl Resource for SystemdSocketService { type Artifact = (PathArtifact, PathArtifact, UserNameArtifact); } @@ -180,7 +179,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 Rc, pub P, pub P, pub bool); +pub struct ServeService(pub D, pub &'static str, pub P, pub P, pub P, pub bool); impl Resource for ServeService { type Artifact = PathArtifact; } @@ -188,7 +187,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/symbols/systemd/user_service.rs b/src/symbols/systemd/user_service.rs index 95af967..fef5692 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, StdCommandRunner, SetuidCommandRunner}; +use crate::command_runner::{CommandRunner, SetuidCommandRunner}; use crate::symbols::Symbol; use async_trait::async_trait; use std::error::Error; @@ -12,7 +12,6 @@ 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> { @@ -21,14 +20,13 @@ 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 = 10; + let mut tries = 5; loop { let result = self.command_runner.run_with_args("systemctl", args).await?; if result.status.success() { @@ -36,15 +34,14 @@ 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" && - stderr != "Failed to connect to user scope bus via local transport: No such file or directory" { + if stderr != "Failed to connect to bus: 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(100)).await; + sleep(Duration::from_millis(500)).await; } } @@ -66,10 +63,10 @@ impl, U: AsRef> UserService<'_, S, U> { return Err( std::str::from_utf8( &self - .root_command_runner + .command_runner .get_output( "journalctl", - args![ /*"--user", format!("--user-unit={}", self.service_name)*/ ], + args!["--user", format!("--user-unit={}", self.service_name)], ) .await?, )? diff --git a/src/templates/nginx/mod.rs b/src/templates/nginx/mod.rs index 8cbcc47..aa2992d 100644 --- a/src/templates/nginx/mod.rs +++ b/src/templates/nginx/mod.rs @@ -27,10 +27,8 @@ mod test { "/challenges_snippet.conf" ), "server { - listen 443 ssl; - listen [::]:443 ssl; - http2 on; - + listen 443 ssl http2; + listen [::]:443 ssl http2; server_name testdomain; include \"/challenges_snippet.conf\"; diff --git a/src/templates/nginx/server.rs b/src/templates/nginx/server.rs index e8ce780..4e35b2d 100644 --- a/src/templates/nginx/server.rs +++ b/src/templates/nginx/server.rs @@ -24,10 +24,8 @@ pub fn server_config, K: AsRef, T: Display, S: ) -> String { format!( "server {{ - listen 443 ssl; - listen [::]:443 ssl; - http2 on; - + listen 443 ssl http2; + listen [::]:443 ssl http2; server_name {}; include \"{}\"; @@ -92,10 +90,12 @@ 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()) } @@ -105,16 +105,19 @@ 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) } diff --git a/src/templates/systemd.rs b/src/templates/systemd.rs index 4fb8aa1..58f84da 100644 --- a/src/templates/systemd.rs +++ b/src/templates/systemd.rs @@ -1,9 +1,8 @@ use std::path::Path; -use std::ffi::OsStr; pub fn socket_service( socket_path: impl AsRef, - exec: &OsStr, + exec: &str, dir: impl AsRef, additional: &str, ) -> String { @@ -19,7 +18,7 @@ Restart=always WantedBy=default.target ", socket_path.as_ref().to_str().unwrap(), - exec.display(), + exec, dir.as_ref().to_str().unwrap(), additional ) @@ -32,7 +31,7 @@ pub fn nodejs_service, S: AsRef>( ) -> String { socket_service( &socket_path, - format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()).as_ref(), + &format!("/usr/bin/nodejs {}", nodejs_path.as_ref().to_str().unwrap()), dir, &format!( "Environment=NODE_ENV=production