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