use std::fmt::{Display, Error, Formatter}; use std::path::Path; #[derive(Clone, Debug, PartialEq, Hash, Eq)] pub struct FpmPoolConfig { max_children: usize, custom: Option, } impl Display for FpmPoolConfig { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { match &self.custom { None => write!(f, "pm.max_children = {}", self.max_children), Some(custom) => write!(f, "pm.max_children = {}\n{}", self.max_children, custom), } } } impl From for FpmPoolConfig { fn from(max_children: usize) -> Self { Self { max_children, custom: None, } } } impl FpmPoolConfig { pub fn new(max_children: usize, custom: impl Into) -> Self { Self { max_children, custom: Some(custom.into()), } } } pub fn fpm_pool_config, S: AsRef>( user_name: U, socket_path: S, config: &FpmPoolConfig, ) -> String { format!( "[{0}] user = {0} group = www-data listen = {1} listen.owner = www-data pm = ondemand catch_workers_output = yes env[PATH] = /usr/local/bin:/usr/bin:/bin {2} ", user_name.as_ref(), socket_path.as_ref().to_str().unwrap(), config ) }