Compare commits

...

2 commits

Author SHA1 Message Date
afa5791d07 Adapt TLSKey to Debian 10 2019-12-06 09:56:28 +01:00
bc74acc4ab Make PHP version configurable 2019-12-05 16:38:22 +01:00
3 changed files with 16 additions and 12 deletions

View file

@ -32,6 +32,9 @@ pub trait Policy {
fn acme_user(&self) -> Cow<'_, str> { fn acme_user(&self) -> Cow<'_, str> {
"acme".into() "acme".into()
} }
fn php_version(&self) -> &'static str {
"7.0"
}
} }
pub struct DefaultPolicy; pub struct DefaultPolicy;
@ -92,9 +95,10 @@ impl<'b, C: 'b + CommandRunner, P: 'b + Policy> SymbolFactory<'b, C, P> {
fn get_php_fpm_pool<'a>(&'a self, user_name: &str) -> impl Symbol + '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);
let php_version = self.policy.php_version();
Hook::new( Hook::new(
File::new( File::new(
format!("/etc/php/7.0/fpm/pool.d/{}.conf", user_name), format!("/etc/php/{}/fpm/pool.d/{}.conf", php_version, user_name),
format!( format!(
"[{0}] "[{0}]
@ -111,7 +115,7 @@ env[PATH] = /usr/local/bin:/usr/bin:/bin
socket.to_str().unwrap() socket.to_str().unwrap()
), ),
), ),
ReloadService::new("php7.0-fpm", self.command_runner), ReloadService::new(format!("php{}-fpm", php_version), self.command_runner),
) )
} }

View file

@ -4,13 +4,13 @@ use std::fmt;
use crate::command_runner::CommandRunner; use crate::command_runner::CommandRunner;
use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner}; use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct ReloadService<'a, C: CommandRunner> { pub struct ReloadService<'a, S, C: CommandRunner> {
service: &'a str, service: S,
command_runner: &'a C, command_runner: &'a C,
} }
impl<'a, C: CommandRunner> ReloadService<'a, C> { impl<'a, S, C: CommandRunner> ReloadService<'a, S, C> {
pub fn new(service: &'a str, command_runner: &'a C) -> Self { pub fn new(service: S, command_runner: &'a C) -> Self {
ReloadService { ReloadService {
service, service,
command_runner, command_runner,
@ -18,7 +18,7 @@ impl<'a, C: CommandRunner> ReloadService<'a, C> {
} }
} }
impl<C: CommandRunner> Symbol for ReloadService<'_, C> { impl<S: AsRef<str>, C: CommandRunner> Symbol for ReloadService<'_, S, C> {
fn target_reached(&self) -> Result<bool, Box<dyn Error>> { fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(true) Ok(true)
} }
@ -26,7 +26,7 @@ impl<C: CommandRunner> Symbol for ReloadService<'_, C> {
fn execute(&self) -> Result<(), Box<dyn Error>> { fn execute(&self) -> Result<(), Box<dyn Error>> {
self self
.command_runner .command_runner
.run_successfully("systemctl", args!["reload-or-restart", self.service]) .run_successfully("systemctl", args!["reload-or-restart", self.service.as_ref()])
} }
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> { fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
@ -41,8 +41,8 @@ impl<C: CommandRunner> Symbol for ReloadService<'_, C> {
} }
} }
impl<C: CommandRunner> fmt::Display for ReloadService<'_, C> { impl<S: AsRef<str>, C: CommandRunner> fmt::Display for ReloadService<'_, S, C> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(f, "Reload service {}", self.service) write!(f, "Reload service {}", self.service.as_ref())
} }
} }

View file

@ -43,7 +43,7 @@ impl<C: CommandRunner> Symbol for TlsKey<'_, C> {
return Ok(false); return Ok(false);
} }
let output = self.command_runner.get_output( let stdout = self.command_runner.get_output(
"openssl", "openssl",
&[ &[
OsStr::new("rsa"), OsStr::new("rsa"),
@ -54,7 +54,7 @@ impl<C: CommandRunner> Symbol for TlsKey<'_, C> {
"-text".as_ref(), "-text".as_ref(),
], ],
)?; )?;
Ok(output.starts_with(format!("Private-Key: ({} bit)\n", self.get_bytes()).as_bytes())) Ok(stdout.ends_with("RSA key ok\n".as_bytes()))
} }
fn execute(&self) -> Result<(), Box<dyn Error>> { fn execute(&self) -> Result<(), Box<dyn Error>> {