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.

35 lines
825 B

7 years ago
7 years ago
5 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
  1. use crate::command_runner::CommandRunner;
  2. use crate::symbols::Symbol;
  3. use std::borrow::Borrow;
  4. use std::error::Error;
  5. use std::marker::PhantomData;
  6. #[derive(Debug)]
  7. pub struct ReloadService<_C, C, S> {
  8. service: S,
  9. command_runner: C,
  10. phantom: PhantomData<_C>,
  11. }
  12. impl<_C, C, S> ReloadService<_C, C, S> {
  13. pub fn new(command_runner: C, service: S) -> Self {
  14. Self {
  15. service,
  16. command_runner,
  17. phantom: PhantomData::default(),
  18. }
  19. }
  20. }
  21. impl<S: AsRef<str>, _C: CommandRunner, C: Borrow<_C>> Symbol for ReloadService<_C, C, S> {
  22. fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
  23. Ok(true)
  24. }
  25. fn execute(&self) -> Result<(), Box<dyn Error>> {
  26. self.command_runner.borrow().run_successfully(
  27. "systemctl",
  28. args!["reload-or-restart", self.service.as_ref()],
  29. )
  30. }
  31. }