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.

43 lines
1.2 KiB

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