More flexible PHP FPM pool config
This commit is contained in:
parent
e8b2f9fc5c
commit
21018bd6f6
4 changed files with 61 additions and 17 deletions
|
|
@ -1,9 +1,40 @@
|
|||
use std::fmt::{Display, Error, Formatter};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Hash, Eq)]
|
||||
pub struct FpmPoolConfig {
|
||||
max_children: usize,
|
||||
custom: Option<String>,
|
||||
}
|
||||
|
||||
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<usize> for FpmPoolConfig {
|
||||
fn from(max_children: usize) -> Self {
|
||||
Self {
|
||||
max_children,
|
||||
custom: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl FpmPoolConfig {
|
||||
pub fn new(max_children: usize, custom: impl Into<String>) -> Self {
|
||||
Self { max_children, custom: Some(custom.into()) }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn fpm_pool_config<U: AsRef<str>, S: AsRef<Path>>(
|
||||
user_name: U,
|
||||
socket_path: S,
|
||||
max_children: usize,
|
||||
config: &FpmPoolConfig,
|
||||
) -> String {
|
||||
format!(
|
||||
"[{0}]
|
||||
|
|
@ -13,12 +44,12 @@ group = www-data
|
|||
listen = {1}
|
||||
listen.owner = www-data
|
||||
pm = ondemand
|
||||
pm.max_children = {2}
|
||||
catch_workers_output = yes
|
||||
env[PATH] = /usr/local/bin:/usr/bin:/bin
|
||||
{2}
|
||||
",
|
||||
user_name.as_ref(),
|
||||
socket_path.as_ref().to_str().unwrap(),
|
||||
max_children,
|
||||
config
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue