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.

55 lines
1.1 KiB

  1. use std::fmt::{Display, Error, Formatter};
  2. use std::path::Path;
  3. #[derive(Clone, Debug, PartialEq, Hash, Eq)]
  4. pub struct FpmPoolConfig {
  5. max_children: usize,
  6. custom: Option<String>,
  7. }
  8. impl Display for FpmPoolConfig {
  9. fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> {
  10. match &self.custom {
  11. None => write!(f, "pm.max_children = {}", self.max_children),
  12. Some(custom) => write!(f, "pm.max_children = {}\n{}", self.max_children, custom),
  13. }
  14. }
  15. }
  16. impl From<usize> for FpmPoolConfig {
  17. fn from(max_children: usize) -> Self {
  18. Self {
  19. max_children,
  20. custom: None,
  21. }
  22. }
  23. }
  24. impl FpmPoolConfig {
  25. pub fn new(max_children: usize, custom: impl Into<String>) -> Self {
  26. Self { max_children, custom: Some(custom.into()) }
  27. }
  28. }
  29. pub fn fpm_pool_config<U: AsRef<str>, S: AsRef<Path>>(
  30. user_name: U,
  31. socket_path: S,
  32. config: &FpmPoolConfig,
  33. ) -> String {
  34. format!(
  35. "[{0}]
  36. user = {0}
  37. group = www-data
  38. listen = {1}
  39. listen.owner = www-data
  40. pm = ondemand
  41. catch_workers_output = yes
  42. env[PATH] = /usr/local/bin:/usr/bin:/bin
  43. {2}
  44. ",
  45. user_name.as_ref(),
  46. socket_path.as_ref().to_str().unwrap(),
  47. config
  48. )
  49. }