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.
49 lines
1.3 KiB
49 lines
1.3 KiB
use std::error::Error;
|
|
use std::fmt;
|
|
|
|
use crate::command_runner::CommandRunner;
|
|
use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
|
|
|
|
pub struct ReloadService<'a, S, C: CommandRunner> {
|
|
service: S,
|
|
command_runner: &'a C,
|
|
}
|
|
|
|
impl<'a, S, C: CommandRunner> ReloadService<'a, S, C> {
|
|
pub fn new(service: S, command_runner: &'a C) -> Self {
|
|
ReloadService {
|
|
service,
|
|
command_runner,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<S: AsRef<str>, C: CommandRunner> Symbol for ReloadService<'_, S, C> {
|
|
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
|
Ok(true)
|
|
}
|
|
|
|
fn execute(&self) -> Result<(), Box<dyn Error>> {
|
|
self.command_runner.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> {
|
|
Box::new(SymbolAction::new(runner, self))
|
|
}
|
|
|
|
fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b>
|
|
where
|
|
Self: 'b,
|
|
{
|
|
Box::new(OwnedSymbolAction::new(runner, *self))
|
|
}
|
|
}
|
|
|
|
impl<S: AsRef<str>, C: CommandRunner> fmt::Display for ReloadService<'_, S, C> {
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
|
|
write!(f, "Reload service {}", self.service.as_ref())
|
|
}
|
|
}
|