A library for writing host-specific, single-binary configuration management and deployment tools
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

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,
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
)
}