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

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<U: AsRef<str>, C: CommandRunner> Symbol for UserSession<'_, U, C> {
async fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
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<dyn Error>> {
self
.command_runner
.run_successfully("loginctl", args!["enable-linger", self.user_name.as_ref()])
.await
}
}