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.

41 lines
929 B

use crate::command_runner::CommandRunner;
use crate::symbols::Symbol;
use async_trait::async_trait;
use std::borrow::Borrow;
use std::error::Error;
use std::marker::PhantomData;
#[derive(Debug)]
pub struct ReloadService<_C, C, S> {
service: S,
command_runner: C,
phantom: PhantomData<_C>,
}
impl<_C, C, S> ReloadService<_C, C, S> {
pub fn new(command_runner: C, service: S) -> Self {
Self {
service,
command_runner,
phantom: PhantomData::default(),
}
}
}
#[async_trait(?Send)]
impl<S: AsRef<str>, _C: CommandRunner, C: Borrow<_C>> Symbol for ReloadService<_C, C, S> {
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
Ok(true)
}
async fn execute(&self) -> Result<(), Box<dyn Error>> {
self
.command_runner
.borrow()
.run_successfully(
"systemctl",
args!["reload-or-restart", self.service.as_ref()],
)
.await
}
}