Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified greenboot health-check #100

Open
wants to merge 11 commits into
base: greenboot-rs
Choose a base branch
from

Conversation

say-paul
Copy link
Member

@say-paul say-paul commented Mar 29, 2023

This will implement the the existing greenboot health check functionality:
Below are the functionality that will be implemented as part of this PR:

  • greenboot params set up- health-check, rollback
  • Healthcheck process - required.d,wanted.d,red.d,green.d
  • Working with grub params - boot_counter,boot_success
  • MOTD
  • jouranld log
  • unit files

@github-advanced-security
Copy link

You have successfully added a new devskim configuration .github/workflows/analysis.yml:analysis_devskim. As part of the setup process, we have scanned this repository and found no existing alerts. In the future, you will see all code scanning alerts on the repository Security tab.

@say-paul
Copy link
Member Author

I getting:
./greenboot health-check Config { max_reboot: 10, watchdog_check_enabled: false, watchdog_grace_period: 24 } INFO greenboot > running required check /usr/lib/greenboot/check/required.d/00_required_scripts_start.sh INFO greenboot > running wanted check /usr/lib/greenboot/check/wanted.d/00_wanted_scripts_start.sh INFO greenboot > greenbbot health-check passed. INFO greenboot > running green check /usr/lib/greenboot/green.d/00_required_scripts_start.sh thread 'main' panicked at 'unable to set grub variable: No such file or directory (os error 2)', src/main.rs:216:39

The grub variable boot_success is not set.

@say-paul say-paul changed the title Simplified greenboot WIP:Simplified greenboot Mar 29, 2023
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
@say-paul say-paul force-pushed the greenboot-rs-continued branch 3 times, most recently from 5dba90c to 665c669 Compare March 30, 2023 06:23
src/main.rs Show resolved Hide resolved
@say-paul say-paul changed the title WIP:Simplified greenboot Simplified greenboot Apr 3, 2023
@say-paul say-paul force-pushed the greenboot-rs-continued branch 4 times, most recently from c836f58 to b4b06c6 Compare April 4, 2023 05:28
@say-paul say-paul changed the title Simplified greenboot Simplified greenboot health-check Apr 4, 2023
@say-paul
Copy link
Member Author

say-paul commented Apr 4, 2023

I getting: ./greenboot health-check Config { max_reboot: 10, watchdog_check_enabled: false, watchdog_grace_period: 24 } INFO greenboot > running required check /usr/lib/greenboot/check/required.d/00_required_scripts_start.sh INFO greenboot > running wanted check /usr/lib/greenboot/check/wanted.d/00_wanted_scripts_start.sh INFO greenboot > greenbbot health-check passed. INFO greenboot > running green check /usr/lib/greenboot/green.d/00_required_scripts_start.sh thread 'main' panicked at 'unable to set grub variable: No such file or directory (os error 2)', src/main.rs:216:39

The grub variable boot_success is not set.

its working now

src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
@miabbott
Copy link
Member

miabbott commented Apr 4, 2023

Would it be possible to break up the one monolithic commit into multiple commits?

It would ease the PR review process and make backing out changes easier.

src/handler/mod.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
Signed-off-by: Sayan Paul <[email protected]>
Accepetd params: healtch-check , rollback

Signed-off-by: Sayan Paul <[email protected]>
greenboot-healtcheck: healthcheck which runs on every boot.
greenboot-rollback: rollback(if healtcheck fails) which is tagged
with systemd-update-done.service that runs, only after a system is updated.

Signed-off-by: Sayan Paul <[email protected]>
 Makefile params:  build,install,check,rpm
 spec - bump from v0.15 series which is bash version of greenboot to
 v0.16.0

Signed-off-by: Sayan Paul <[email protected]>
CI runs formatting spellcheck and unit tests.
packit build rpm for fedora and centos

    Signed-off-by: Sayan Paul <[email protected]>

Signed-off-by: Sayan Paul <[email protected]>
devcontainer has all the necessary libaries installed to run test
and build greenboot.

Signedff-by: Sayan Paul <[email protected]>
@say-paul
Copy link
Member Author

I have major reservations about how get_boot_counter is handled, plus other minor things

I have modified this too.

"/etc/motd.d/boot-status",
format!("Greenboot {state}.").as_bytes(),
)?;
Ok(())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the last statement already returns a Result, then there is no need for the Ok below, just map the error to the type that we are returning

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense

src/main.rs Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/main.rs Outdated Show resolved Hide resolved
src/handler/mod.rs Outdated Show resolved Hide resolved
@say-paul say-paul requested a review from 7flying April 18, 2024 10:10
saving 2 Bytes of ram!!

Signed-off-by: Sayan Paul <[email protected]>
@say-paul say-paul mentioned this pull request Apr 18, 2024
@say-paul say-paul dismissed nullr0ute’s stale review April 18, 2024 11:34

moving the log related comments to issue #149

bail!("countdown ended, check greenboot-rollback status")
};
}
}
Copy link
Member

@runcom runcom Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't you compress it to:

if !force && if let Some(t) = get_boot_counter()? && t <= 0 {

I don't like 3 nested if(s) - so, up to others for style too...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly whats suggested..
but able to reduce the nested loop in : ee8bd08

}
}
bail!("Rollback not initiated");
}
Copy link
Member

@runcom runcom Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be better rewritten as:

pub fn handle_rollback() -> Result<()> {
    let boot_counter = get_boot_counter()?;
    if boot_counter <= 0 {
        log::info!("Greenboot will now attempt to rollback");
        Command::new("rpm-ostree").arg("rollback").status()?;
        return Ok(());
    }
    bail!("Rollback not initiated");
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in : ee8bd08

set_grub_var("boot_success", 0)?;
}
Ok(())
}
Copy link
Member

@runcom runcom Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pub fn set_boot_status(success: bool) -> Result<()> {
    if success {
        set_grub_var("boot_success", 1)?;
        unset_boot_counter()?;
        return Ok(());
    }
    set_grub_var("boot_success", 0)?
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in ee8bd08

src/main.rs Outdated
#[clap(subcommand)]
command: Commands,
}
#[derive(Debug, Deserialize)]
///config params for greenboot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bothers me personally 😛 consistency with spaces after /// - the code is a mix afaics

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in: ee8bd08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.