|
|
@ -9,14 +9,14 @@ use symbols::cron::Cron; |
|
|
|
use symbols::file::File;
|
|
|
|
use symbols::git::checkout::GitCheckout;
|
|
|
|
use symbols::hook::Hook;
|
|
|
|
use symbols::list::ListAction;
|
|
|
|
use symbols::list::List;
|
|
|
|
use symbols::mariadb::{DatabaseDump, MariaDBDatabase, MariaDBUser};
|
|
|
|
use symbols::nginx::server::{php_server_config_snippet, server_config, NginxServer};
|
|
|
|
use symbols::owner::Owner;
|
|
|
|
use symbols::stored_directory::{StorageDirection, StoredDirectory};
|
|
|
|
use symbols::systemd::reload::ReloadService;
|
|
|
|
use symbols::tls::SelfSignedTlsCert;
|
|
|
|
use symbols::{Action, Symbol, SymbolRunner};
|
|
|
|
use symbols::{Symbol, SymbolRunner};
|
|
|
|
|
|
|
|
pub trait Policy {
|
|
|
|
fn user_name_for_host(&self, host_name: &'static str) -> String;
|
|
|
@ -57,42 +57,37 @@ impl<'b, C: 'b + CommandRunner, R: 'b + SymbolRunner, P: 'b + Policy> SymbolFact |
|
|
|
&'c self,
|
|
|
|
host: &'static str,
|
|
|
|
nginx_server_symbol: S,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(ListAction::new(vec![
|
|
|
|
Box::new(SelfSignedTlsCert::new(host.into(), self.command_runner))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
Box::new(Hook::new(
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
List::from((
|
|
|
|
SelfSignedTlsCert::new(host.into(), self.command_runner),
|
|
|
|
Hook::new(
|
|
|
|
nginx_server_symbol,
|
|
|
|
ReloadService::new("nginx", self.command_runner),
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
Box::new(AcmeCert::new(host.into(), &self.acme_command_runner))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
Box::new(Hook::new(
|
|
|
|
),
|
|
|
|
AcmeCert::new(host.into(), &self.acme_command_runner),
|
|
|
|
Hook::new(
|
|
|
|
AcmeCertChain::new(host.into(), &self.acme_command_runner),
|
|
|
|
ReloadService::new("nginx", self.command_runner),
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
]))
|
|
|
|
),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(File::new(
|
|
|
|
pub fn get_nginx_acme_challenge_config<'a>(&'a self) -> impl Symbol + 'a {
|
|
|
|
File::new(
|
|
|
|
"/etc/nginx/snippets/acme-challenge.conf",
|
|
|
|
"location ^~ /.well-known/acme-challenge/ {
|
|
|
|
alias /home/acme/challenges/;
|
|
|
|
try_files $uri =404;
|
|
|
|
}",
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_php_fpm_pool_socket_path<'a>(&'a self, user_name: &str) -> String {
|
|
|
|
format!("/run/php/{}.sock", user_name)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> Box<dyn Action + 'a> {
|
|
|
|
fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> impl Symbol + 'a {
|
|
|
|
let socket = self.get_php_fpm_pool_socket_path(user_name);
|
|
|
|
Box::new(Hook::new(
|
|
|
|
Hook::new(
|
|
|
|
File::new(
|
|
|
|
format!("/etc/php/7.0/fpm/pool.d/{}.conf", user_name),
|
|
|
|
format!(
|
|
|
@ -111,8 +106,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
),
|
|
|
|
),
|
|
|
|
ReloadService::new("php7.0-fpm", self.command_runner),
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn serve_php<'a>(
|
|
|
@ -120,10 +114,10 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
host_name: &'static str,
|
|
|
|
root_dir: Cow<'a, str>,
|
|
|
|
additional_config: &'a str,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
let user_name = self.policy.user_name_for_host(host_name);
|
|
|
|
let socket = self.get_php_fpm_pool_socket_path(&user_name);
|
|
|
|
Box::new(ListAction::new(vec![
|
|
|
|
List::from((
|
|
|
|
self.get_php_fpm_pool(&user_name),
|
|
|
|
self.get_nginx_acme_server(
|
|
|
|
host_name,
|
|
|
@ -135,22 +129,22 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
additional_config,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]))
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn serve_wordpress<'a>(
|
|
|
|
&'a self,
|
|
|
|
host_name: &'static str,
|
|
|
|
root_dir: Cow<'a, str>,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
self.serve_php(
|
|
|
|
host_name,
|
|
|
|
root_dir,
|
|
|
|
"
|
|
|
|
location / {{
|
|
|
|
try_files $uri $uri/ /index.php?$args;
|
|
|
|
}}
|
|
|
|
",
|
|
|
|
location / {{
|
|
|
|
try_files $uri $uri/ /index.php?$args;
|
|
|
|
}}
|
|
|
|
",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
@ -158,10 +152,10 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
&'a self,
|
|
|
|
host_name: &'static str,
|
|
|
|
root_dir: &'static str,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
let user_name = self.policy.user_name_for_host(host_name);
|
|
|
|
let socket = self.get_php_fpm_pool_socket_path(&user_name);
|
|
|
|
Box::new(ListAction::new(vec![
|
|
|
|
List::from((
|
|
|
|
self.get_php_fpm_pool(&user_name),
|
|
|
|
self.get_nginx_acme_server(host_name,
|
|
|
|
NginxServer::new(
|
|
|
@ -190,14 +184,14 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
socket)),
|
|
|
|
self.command_runner
|
|
|
|
))
|
|
|
|
]))
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn serve_nextcloud<'a>(
|
|
|
|
&'a self,
|
|
|
|
host_name: &'static str,
|
|
|
|
root_dir: Cow<'a, str>,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
self.serve_php(
|
|
|
|
host_name,
|
|
|
|
root_dir,
|
|
|
@ -257,14 +251,14 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
&'a self,
|
|
|
|
host_name: &'static str,
|
|
|
|
target: &'static str,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
self.get_nginx_acme_server(
|
|
|
|
host_name,
|
|
|
|
NginxServer::new_redir(host_name, target, self.command_runner),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn serve_static<'a>(&'a self, host_name: &'static str, dir: &'a str) -> Box<dyn Action + 'a> {
|
|
|
|
pub fn serve_static<'a>(&'a self, host_name: &'static str, dir: &'a str) -> impl Symbol + 'a {
|
|
|
|
self.get_nginx_acme_server(
|
|
|
|
host_name,
|
|
|
|
NginxServer::new_static(host_name, dir, self.command_runner),
|
|
|
@ -275,47 +269,42 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
&'a self,
|
|
|
|
storage_name: &'static str,
|
|
|
|
target: T,
|
|
|
|
) -> (Box<dyn Action + 'a>, Box<dyn Action + 'a>) {
|
|
|
|
) -> (impl Symbol + 'a, impl Symbol + 'a) {
|
|
|
|
let data = SimpleStorage::new("/root/data".to_string(), storage_name.to_string());
|
|
|
|
let string_target = target.into();
|
|
|
|
(
|
|
|
|
Box::new(StoredDirectory::new(
|
|
|
|
StoredDirectory::new(
|
|
|
|
string_target.clone().into(),
|
|
|
|
data.clone(),
|
|
|
|
StorageDirection::Save,
|
|
|
|
self.command_runner,
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
Box::new(StoredDirectory::new(
|
|
|
|
),
|
|
|
|
StoredDirectory::new(
|
|
|
|
string_target.into(),
|
|
|
|
data.clone(),
|
|
|
|
StorageDirection::Load,
|
|
|
|
self.command_runner,
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_mariadb_database<'a>(&'a self, name: &'static str) -> Box<dyn Action + 'a> {
|
|
|
|
pub fn get_mariadb_database<'a>(&'a self, name: &'static str) -> impl Symbol + 'a {
|
|
|
|
let db_dump = SimpleStorage::new("/root/data".to_string(), format!("{}.sql", name));
|
|
|
|
Box::new(ListAction::new(vec![
|
|
|
|
Box::new(MariaDBDatabase::new(
|
|
|
|
List::from((
|
|
|
|
MariaDBDatabase::new(
|
|
|
|
name.into(),
|
|
|
|
db_dump
|
|
|
|
.read_filename()
|
|
|
|
.expect("Initial db dump missing")
|
|
|
|
.into(),
|
|
|
|
self.command_runner,
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
Box::new(DatabaseDump::new(name, db_dump, self.command_runner))
|
|
|
|
.into_action(self.symbol_runner),
|
|
|
|
]))
|
|
|
|
),
|
|
|
|
DatabaseDump::new(name, db_dump, self.command_runner),
|
|
|
|
))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_mariadb_user<'a>(&'a self, user_name: &'static str) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(MariaDBUser::new(user_name.into(), self.command_runner))
|
|
|
|
.into_action(self.symbol_runner)
|
|
|
|
pub fn get_mariadb_user<'a>(&'a self, user_name: &'static str) -> impl Symbol + 'a {
|
|
|
|
MariaDBUser::new(user_name.into(), self.command_runner)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_git_checkout<'a, T: 'a + AsRef<str>>(
|
|
|
@ -323,37 +312,27 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin |
|
|
|
target: T,
|
|
|
|
source: &'a str,
|
|
|
|
branch: &'a str,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(GitCheckout::new(
|
|
|
|
target,
|
|
|
|
source,
|
|
|
|
branch,
|
|
|
|
self.command_runner,
|
|
|
|
))
|
|
|
|
.into_action(self.symbol_runner)
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
GitCheckout::new(target, source, branch, self.command_runner)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_owner<'a, F: 'a + AsRef<str>>(
|
|
|
|
&'a self,
|
|
|
|
file: F,
|
|
|
|
user: &'a str,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(Owner::new(file, user.into(), self.command_runner)).into_action(self.symbol_runner)
|
|
|
|
pub fn get_owner<'a, F: 'a + AsRef<str>>(&'a self, file: F, user: &'a str) -> impl Symbol + 'a {
|
|
|
|
Owner::new(file, user.into(), self.command_runner)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_file<'a, F: 'a + Deref<Target = str>, Q: 'a + AsRef<Path>>(
|
|
|
|
&'a self,
|
|
|
|
path: Q,
|
|
|
|
content: F,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(File::new(path, content)).into_action(self.symbol_runner)
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
File::new(path, content)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_cron<'a, T: 'a + Deref<Target = str>, U: 'a + Deref<Target = str>>(
|
|
|
|
&'a self,
|
|
|
|
user: U,
|
|
|
|
content: T,
|
|
|
|
) -> Box<dyn Action + 'a> {
|
|
|
|
Box::new(Cron::new(user, content, self.command_runner)).into_action(self.symbol_runner)
|
|
|
|
) -> impl Symbol + 'a {
|
|
|
|
Cron::new(user, content, self.command_runner)
|
|
|
|
}
|
|
|
|
}
|