Browse Source

Add PHP-related factory functions

master
Adrian Heine 7 years ago
parent
commit
c17267ada3
  1. 8
      src/factory.rs
  2. 34
      src/symbols/factory.rs
  3. 2
      src/symbols/nginx/server.rs

8
src/factory.rs

@ -1,11 +1,8 @@
use regex::Regex;
use std::collections::HashMap;
use command_runner::CommandRunner;
use command_runner::StdCommandRunner;
use loggers::StdErrLogger;
use repository::{DispatchingSymbolRepository, SymbolRepository};
use repository::SymbolRepository;
use resources::Resource;
use schema::{NonRepeatingSymbolRunner, ReportingSymbolRunner, RequirementsResolvingSymbolRunner};
use symbols::{Symbol, SymbolRunner};
@ -13,8 +10,7 @@ use symbols::dir::Dir;
use symbols::list::List;
use symbols::owner::Owner;
use symbols::systemd::user_session::SystemdUserSession;
use symbols::tls::TlsCsr;
use symbols::tls::TlsKey;
use symbols::tls::{TlsCsr, TlsKey};
use symbols::user::{User, UserAdder};
use symbols::user::SystemUserAdder;

34
src/symbols/factory.rs

@ -4,6 +4,7 @@ use symbols::acme::{AcmeCert, AcmeCertChain};
use symbols::file::File;
use symbols::hook::Hook;
use symbols::list::ListAction;
use symbols::nginx::server::NginxServer;
use symbols::systemd::reload::ReloadService;
use symbols::tls::SelfSignedTlsCert;
@ -52,4 +53,37 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner> SymbolFactory<'b, C, R> {
}"
)).into_action(self.symbol_runner)
}
fn get_php_fpm_pool_socket_path<'a>(&'a self, user_name: &'static str) -> String {
format!("/run/php/{}.sock", user_name)
}
pub fn get_php_fpm_pool<'a>(&'a self, user_name: &'static str) -> Box<Action + 'a> {
let socket = self.get_php_fpm_pool_socket_path(user_name);
Box::new(Hook::new(
File::new(
format!("/etc/php/7.0/fpm/pool.d/{}.conf", user_name),
format!(
"[{0}]
user = {0}
group = www-data
listen = {1}
listen.owner = www-data
pm = ondemand
pm.max_children = 10"
, user_name, socket)),
ReloadService::new("php7.0-fpm", self.command_runner)
)).into_action(self.symbol_runner)
}
pub fn get_nginx_php_server<'a>(&'a self, host_name: &'static str, user_name: &'static str, root_dir: &'static str) -> NginxServer<'a, C, String> {
let socket = self.get_php_fpm_pool_socket_path(user_name);
NginxServer::new_php(
host_name,
socket.into(),
root_dir,
self.command_runner
)
}
}

2
src/symbols/nginx/server.rs

@ -100,7 +100,7 @@ location @proxy {{
NginxServer::new(domain, content, command_runner)
}
pub fn new_php(domain: &'a str, socket_path: &'a str, static_path: &'a str, command_runner: &'a C) -> Self {
pub fn new_php(domain: &'a str, socket_path: Cow<'a, str>, static_path: &'a str, command_runner: &'a C) -> Self {
let content = server_config(domain, &format!("
root {};
index index.html index.php;

Loading…
Cancel
Save