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.

49 lines
1.3 KiB

7 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
7 years ago
5 years ago
7 years ago
5 years ago
7 years ago
7 years ago
7 years ago
  1. use std::error::Error;
  2. use std::fmt;
  3. use crate::command_runner::CommandRunner;
  4. use crate::symbols::{Action, OwnedSymbolAction, Symbol, SymbolAction, SymbolRunner};
  5. pub struct ReloadService<'a, S, C: CommandRunner> {
  6. service: S,
  7. command_runner: &'a C,
  8. }
  9. impl<'a, S, C: CommandRunner> ReloadService<'a, S, C> {
  10. pub fn new(service: S, command_runner: &'a C) -> Self {
  11. ReloadService {
  12. service,
  13. command_runner,
  14. }
  15. }
  16. }
  17. impl<S: AsRef<str>, C: CommandRunner> Symbol for ReloadService<'_, S, C> {
  18. fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
  19. Ok(true)
  20. }
  21. fn execute(&self) -> Result<(), Box<dyn Error>> {
  22. self.command_runner.run_successfully(
  23. "systemctl",
  24. args!["reload-or-restart", self.service.as_ref()],
  25. )
  26. }
  27. fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
  28. Box::new(SymbolAction::new(runner, self))
  29. }
  30. fn into_action<'b>(self: Box<Self>, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b>
  31. where
  32. Self: 'b,
  33. {
  34. Box::new(OwnedSymbolAction::new(runner, *self))
  35. }
  36. }
  37. impl<S: AsRef<str>, C: CommandRunner> fmt::Display for ReloadService<'_, S, C> {
  38. fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
  39. write!(f, "Reload service {}", self.service.as_ref())
  40. }
  41. }