Use OsStr for systemd unit exec value

This commit is contained in:
Adrian Heine 2025-12-09 22:08:22 +01:00
parent 36b85ff350
commit d363254f6e
3 changed files with 10 additions and 8 deletions

View file

@ -456,11 +456,11 @@ impl<D, P: AsRef<Path>> ImplementationBuilder<SystemdSocketService<D, P>> for De
FileSymbol::new( FileSymbol::new(
conf_path.clone_rc(), conf_path.clone_rc(),
if resource.4 { if resource.4 {
systemd_nodejs_service(&resource.2, socket_path, &resource.3) systemd_nodejs_service(resource.2.as_ref(), socket_path, &resource.3)
} else { } else {
systemd_socket_service( systemd_socket_service(
socket_path, socket_path,
resource.2.as_ref().to_str().unwrap(), &resource.2,
&resource.3, &resource.3,
"", "",
) )

View file

@ -5,6 +5,7 @@ use crate::artifacts::{
use crate::templates::php::FpmPoolConfig; use crate::templates::php::FpmPoolConfig;
use std::hash::Hash; use std::hash::Hash;
use std::path::Path; use std::path::Path;
use std::ffi::OsStr;
pub trait Resource { pub trait Resource {
type Artifact; type Artifact;
@ -136,7 +137,7 @@ impl Resource for User {
} }
#[derive(Debug, Hash, PartialEq, Eq)] #[derive(Debug, Hash, PartialEq, Eq)]
pub struct SystemdSocketService<D, P>(pub D, pub &'static str, pub P, pub P, pub bool); pub struct SystemdSocketService<D, P>(pub D, pub &'static str, pub Rc<OsStr>, pub P, pub bool);
impl<D, P> Resource for SystemdSocketService<D, P> { impl<D, P> Resource for SystemdSocketService<D, P> {
type Artifact = (PathArtifact, PathArtifact, UserNameArtifact); type Artifact = (PathArtifact, PathArtifact, UserNameArtifact);
} }
@ -179,7 +180,7 @@ impl<D, P, C> Resource for ServePhp<D, P, C> {
// Domain, service name, exec, static, dir // Domain, service name, exec, static, dir
#[derive(Debug, Hash, PartialEq, Eq)] #[derive(Debug, Hash, PartialEq, Eq)]
pub struct ServeService<D, P>(pub D, pub &'static str, pub P, pub P, pub P, pub bool); pub struct ServeService<D, P>(pub D, pub &'static str, pub Rc<OsStr>, pub P, pub P, pub bool);
impl<D, P> Resource for ServeService<D, P> { impl<D, P> Resource for ServeService<D, P> {
type Artifact = PathArtifact; type Artifact = PathArtifact;
} }
@ -187,7 +188,7 @@ impl<D> ServeService<D, Rc<Path>> {
pub fn new( pub fn new(
domain: D, domain: D,
service_name: &'static str, service_name: &'static str,
exec: impl Into<Rc<Path>>, exec: impl Into<Rc<OsStr>>,
static_path: impl Into<Rc<Path>>, static_path: impl Into<Rc<Path>>,
working_directory: impl Into<Rc<Path>>, working_directory: impl Into<Rc<Path>>,
is_nodejs: bool, is_nodejs: bool,

View file

@ -1,8 +1,9 @@
use std::path::Path; use std::path::Path;
use std::ffi::OsStr;
pub fn socket_service( pub fn socket_service(
socket_path: impl AsRef<Path>, socket_path: impl AsRef<Path>,
exec: &str, exec: &OsStr,
dir: impl AsRef<Path>, dir: impl AsRef<Path>,
additional: &str, additional: &str,
) -> String { ) -> String {
@ -18,7 +19,7 @@ Restart=always
WantedBy=default.target WantedBy=default.target
", ",
socket_path.as_ref().to_str().unwrap(), socket_path.as_ref().to_str().unwrap(),
exec, exec.display(),
dir.as_ref().to_str().unwrap(), dir.as_ref().to_str().unwrap(),
additional additional
) )
@ -31,7 +32,7 @@ pub fn nodejs_service<N: AsRef<Path>, S: AsRef<Path>>(
) -> String { ) -> String {
socket_service( socket_service(
&socket_path, &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, dir,
&format!( &format!(
"Environment=NODE_ENV=production "Environment=NODE_ENV=production