Skip to content

Commit

Permalink
prairiedog: extend reboot-to-reconcile to support marker files
Browse files Browse the repository at this point in the history
  • Loading branch information
piyush-jena committed Nov 13, 2024
1 parent d090ae7 commit dac5020
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/systemd/systemd-tmpfiles.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
d /run/cache 0755 root root -
d /run/lock 0755 root root -
d /run/prairiedog 0755 root root -
L /var/lock - - - - /run/lock
Z /var/lib/systemd 0755 root root -
z /var/lib/systemd/random-seed 600 root root -
Expand Down
30 changes: 29 additions & 1 deletion sources/api/prairiedog/src/bootconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const DEFAULT_BOOT_SETTINGS: BootSettings = BootSettings {
kernel_parameters: None,
init_parameters: None,
};
const REBOOT_REQD_MARKER_DIR: &str = "/run/prairiedog";

#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "kebab-case")]
Expand Down Expand Up @@ -295,6 +296,29 @@ fn boot_config_to_boot_settings_json(bootconfig_str: &str) -> Result<String> {
serde_json::to_string(&boot_settings).context(error::OutputJsonSnafu)
}

/// Given a path, check if the directory or its subdirectories contains files
fn contains_files(dir: &Path) -> bool {
let mut ans: bool = false;

// Check if the path is a directory
if dir.is_dir() {
for entry in fs::read_dir(dir).unwrap() {
let entry = entry.unwrap();
let path = entry.path();

// If the dentry is a subdirectory then call this function for that directory
if path.is_dir() {
ans |= contains_files(&path);
} else {
// file found
return true;
}
}
}

return ans;
}

/// Decides whether the host should be rebooted to have its boot settings take effect
pub(crate) fn is_reboot_required<P>(config_path: P) -> Result<bool>
where
Expand All @@ -307,12 +331,16 @@ where

let new_boot_settings = get_boot_config_settings(config_path)?.unwrap_or(DEFAULT_BOOT_SETTINGS);

let reboot_required = if new_boot_settings.reboot_to_reconcile.unwrap_or(false) {
let mut reboot_required = if new_boot_settings.reboot_to_reconcile.unwrap_or(false) {
boot_settings_change_requires_reboot(&old_boot_settings, &new_boot_settings)
} else {
false
};

let marker_dir = Path::new(REBOOT_REQD_MARKER_DIR);
let has_files = contains_files(marker_dir);

reboot_required = reboot_required | has_files;
Ok(reboot_required)
}

Expand Down

0 comments on commit dac5020

Please sign in to comment.