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.

36 lines
956 B

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