Provide an implementation for systemd-tmpfiles.

Co-authored-by: aanderse <aaron@fosslib.net>
Co-authored-by: jfroche <jfroche@pyxel.be>
This commit is contained in:
r-vdp 2023-10-12 11:13:08 +02:00
parent 549bc38339
commit e51a1d3ed0
No known key found for this signature in database
6 changed files with 88 additions and 3 deletions

View file

@ -1,5 +1,6 @@
mod etc_files;
mod services;
mod tmp_files;
use anyhow::Result;
use serde::{Deserialize, Serialize};
@ -80,6 +81,17 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
match etc_files::activate(store_path, old_state.file_tree, ephemeral) {
Ok(etc_tree) => {
log::info!("Activating tmp files...");
match tmp_files::activate() {
Ok(_) => {
log::debug!("Successfully created tmp files");
}
Err(e) => {
log::error!("Error during activation of tmp files");
log::error!("{e}");
}
};
log::info!("Activating systemd services...");
match services::activate(store_path, old_state.services, ephemeral) {
Ok(services) => State {
@ -104,6 +116,7 @@ pub fn activate(store_path: &StorePath, ephemeral: bool) -> Result<()> {
}
}
.write_to_file(state_file)?;
Ok(())
}
@ -184,6 +197,7 @@ pub fn deactivate() -> Result<()> {
}
}
.write_to_file(state_file)?;
Ok(())
}

29
src/activate/tmp_files.rs Normal file
View file

@ -0,0 +1,29 @@
use crate::activate;
use super::ActivationResult;
use std::process;
type TmpFilesActivationResult = ActivationResult<()>;
pub fn activate() -> TmpFilesActivationResult {
let mut cmd = process::Command::new("systemd-tmpfiles");
cmd.arg("--create")
.arg("--remove")
.arg("/etc/tmpfiles.d/00-system-manager.conf");
let output = cmd
.stdout(process::Stdio::inherit())
.stderr(process::Stdio::inherit())
.output()
.expect("Error forking process");
output.status.success().then_some(()).ok_or_else(|| {
activate::ActivationError::WithPartialResult {
result: (),
source: anyhow::anyhow!(
"Error while creating tmpfiles\nstdout: {}\nstderr: {}",
String::from_utf8_lossy(output.stdout.as_ref()),
String::from_utf8_lossy(output.stderr.as_ref())
),
}
})
}