use crate::command_runner::CommandRunner; use crate::symbols::Symbol; use async_trait::async_trait; 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 const fn new(user_name: U, command_runner: &'a C) -> Self { Self { user_name, command_runner, } } } #[async_trait(?Send)] impl, C: CommandRunner> Symbol for UserSession<'_, U, C> { async 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` } async fn execute(&self) -> Result<(), Box> { self .command_runner .run_successfully("loginctl", args!["enable-linger", self.user_name.as_ref()]) .await } }