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.

33 lines
873 B

8 years ago
5 years ago
8 years ago
5 years ago
8 years ago
5 years ago
8 years ago
7 years ago
8 years ago
5 years ago
5 years ago
8 years ago
  1. use crate::command_runner::CommandRunner;
  2. use crate::symbols::Symbol;
  3. use std::error::Error;
  4. use std::path::Path;
  5. #[derive(Debug)]
  6. pub struct UserSession<'a, U, C> {
  7. user_name: U,
  8. command_runner: &'a C,
  9. }
  10. impl<'a, U, C> UserSession<'a, U, C> {
  11. pub fn new(user_name: U, command_runner: &'a C) -> Self {
  12. Self {
  13. user_name,
  14. command_runner,
  15. }
  16. }
  17. }
  18. impl<U: AsRef<str>, C: CommandRunner> Symbol for UserSession<'_, U, C> {
  19. fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
  20. let path = Path::new("/var/lib/systemd/linger").join(self.user_name.as_ref());
  21. Ok(path.exists())
  22. // Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes`
  23. }
  24. fn execute(&self) -> Result<(), Box<dyn Error>> {
  25. self
  26. .command_runner
  27. .run_successfully("loginctl", args!["enable-linger", self.user_name.as_ref()])
  28. }
  29. }