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.

40 lines
1.1 KiB

use std::error::Error;
use std::fmt;
use command_runner::CommandRunner;
use symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
pub struct ReloadService<'a, C: 'a + CommandRunner> {
service: &'a str,
command_runner: &'a C
}
impl<'a, C: CommandRunner> ReloadService<'a, C> {
pub fn new(service: &'a str, command_runner: &'a C) -> Self {
ReloadService { service, command_runner }
}
}
impl<'a, C: CommandRunner> Symbol for ReloadService<'a, C> {
fn target_reached(&self) -> Result<bool, Box<Error>> {
Ok(true)
}
fn execute(&self) -> Result<(), Box<Error>> {
self.command_runner.run_successfully("systemctl", &["reload-or-restart", self.service])
}
fn as_action<'b>(&'b self, runner: &'b SymbolRunner) -> Box<Action + 'b> {
Box::new(SymbolAction::new(runner, self))
}
fn into_action<'b>(self: Box<Self>, runner: &'b SymbolRunner) -> Box<Action + 'b> where Self: 'b {
Box::new(OwnedSymbolAction::new(runner, *self))
}
}
impl<'a, C: CommandRunner> fmt::Display for ReloadService<'a, C> {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(),fmt::Error>{
write!(f, "Reload service {}", self.service)
}
}