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 Jan 17, 2025
1 parent 467f251 commit 2ba9e9c
Show file tree
Hide file tree
Showing 2 changed files with 31 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
31 changes: 30 additions & 1 deletion sources/api/prairiedog/src/bootconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use std::{fs, io};
// Boot config related consts
const BOOTCONFIG_INITRD_PATH: &str = "/var/lib/bottlerocket/bootconfig.data";
const PROC_BOOTCONFIG: &str = "/proc/bootconfig";
const REBOOT_REQD_MARKER_DIR: &str = "/run/prairiedog";
const DEFAULT_BOOTCONFIG_STR: &str = r#"
kernel = ""
init = ""
Expand Down Expand Up @@ -295,6 +296,30 @@ 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 dentry = entry.unwrap();
let path = dentry.path();

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

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 +332,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 |= has_files;
Ok(reboot_required)
}

Expand Down

0 comments on commit 2ba9e9c

Please sign in to comment.