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

2 years ago
  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 {
  27. max_children,
  28. custom: Some(custom.into()),
  29. }
  30. }
  31. }
  32. pub fn fpm_pool_config<U: AsRef<str>, S: AsRef<Path>>(
  33. user_name: U,
  34. socket_path: S,
  35. config: &FpmPoolConfig,
  36. ) -> String {
  37. format!(
  38. "[{0}]
  39. user = {0}
  40. group = www-data
  41. listen = {1}
  42. listen.owner = www-data
  43. pm = ondemand
  44. catch_workers_output = yes
  45. env[PATH] = /usr/local/bin:/usr/bin:/bin
  46. {2}
  47. ",
  48. user_name.as_ref(),
  49. socket_path.as_ref().to_str().unwrap(),
  50. config
  51. )
  52. }