use crate::command_runner::CommandRunner; use crate::symbols::Symbol; use std::error::Error; use std::path::Path; #[derive(Debug)] pub struct UserSession<'a, U, C> { user_name: U, command_runner: &'a C, } impl<'a, U, C> UserSession<'a, U, C> { pub fn new(user_name: U, command_runner: &'a C) -> Self { Self { user_name, command_runner, } } } impl, C: CommandRunner> Symbol for UserSession<'_, U, C> { fn target_reached(&self) -> Result> { let path = Path::new("/var/lib/systemd/linger").join(self.user_name.as_ref()); Ok(path.exists()) // Could also do `loginctl show-user ${self.user_name} | grep -F 'Linger=yes` } fn execute(&self) -> Result<(), Box> { self .command_runner .run_successfully("loginctl", args!["enable-linger", self.user_name.as_ref()]) } }