### Configure Greenboot Settings Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Example of the /etc/greenboot/greenboot.conf INI file, used to define retry attempts, disable specific checks, and configure watchdog behavior. ```ini GREENBOOT_MAX_BOOT_ATTEMPTS=3 DISABLED_HEALTHCHECKS=() GREENBOOT_WATCHDOG_CHECK_ENABLED=true GREENBOOT_WATCHDOG_GRACE_PERIOD=24 ``` -------------------------------- ### Integrate Greenboot into Container Images Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Instructions for installing and configuring greenboot within a bootc container image, including setting up health check scripts and enabling systemd services. ```dockerfile FROM quay.io/fedora/fedora-bootc:latest RUN dnf install -y greenboot greenboot-default-health-checks && dnf clean all COPY check-app-health.sh /etc/greenboot/check/required.d/20_check_app_health.sh RUN chmod 755 /etc/greenboot/check/required.d/20_check_app_health.sh RUN systemctl enable greenboot-healthcheck.service ``` ```bash podman build -t myimage:latest . podman push myimage:latest registry.example.com/myimage:latest bootc switch registry.example.com/myimage:latest systemctl reboot ``` -------------------------------- ### Execute Greenboot CLI Commands Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Demonstrates how to manually trigger health checks with specific log levels and how to set a manual rollback trigger for the next boot cycle. ```bash /usr/libexec/greenboot/greenboot health-check /usr/libexec/greenboot/greenboot --log-level debug health-check /usr/libexec/greenboot/greenboot --log-level trace health-check /usr/libexec/greenboot/greenboot set-rollback-trigger ``` -------------------------------- ### Manage GRUB Environment Variables Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Utilities to interact with GRUB environment variables, including the boot counter, rollback triggers, and boot status. These are essential for managing multi-stage boot recovery. ```rust use greenboot::{get_boot_counter, set_boot_counter, set_boot_status, set_rollback_trigger}; match get_boot_counter() { Ok(Some(counter)) => println!("Boot counter: {}", counter), _ => (), } set_boot_counter(3)?; set_boot_status(true)?; set_rollback_trigger()?; ``` -------------------------------- ### Manage GRUB Boot Counter Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Commands to interact with GRUB environment variables, allowing users to inspect or reset the boot counter used for rollback logic. ```bash grub2-editenv /boot/grub2/grubenv list grub2-editenv /boot/grub2/grubenv list | grep boot_counter grub2-editenv /boot/grub2/grubenv unset boot_counter ``` -------------------------------- ### Manage Boot Partition Mount State Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Functions to check and modify the mount state of the /boot partition, which is required for modifying GRUB configuration files safely. ```rust use greenboot::{is_boot_rw, remount_boot_rw, remount_boot_ro}; if let Ok(false) = is_boot_rw() { remount_boot_rw()?; // Perform operations remount_boot_ro()?; } ``` -------------------------------- ### Create Green Success Script Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt A script executed after all health checks have passed. Useful for logging or notifying external monitoring systems of a successful boot. ```bash #!/bin/bash echo "System boot successful at $(date)" >> /var/log/greenboot-success.log curl -X POST "https://monitoring.example.com/api/boot-success" \ -H "Content-Type: application/json" \ -d "{\"hostname\": \"$(hostname)\", \"timestamp\": \"$(date -Iseconds)\"}" \ || true ``` -------------------------------- ### Execute Health Checks via Rust API Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Demonstrates how to invoke the Greenboot diagnostic runner using the Rust library. It allows passing a list of disabled scripts and handles the result of the health check operation. ```rust use greenboot::run_diagnostics; let result = run_diagnostics(vec![]); match result { Ok(missing_disabled) => { if !missing_disabled.is_empty() { println!("Warning: disabled scripts not found: {:?}", missing_disabled); } println!("All health checks passed"); } Err(e) => { eprintln!("Health check failed: {}", e); } } let disabled = vec![ "01_repository_dns_check.sh".to_string(), "02_watchdog.sh".to_string(), ]; let result = run_diagnostics(disabled); ``` -------------------------------- ### Create Red Failure Diagnostic Script Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt A bash script placed in /etc/greenboot/red.d/ that executes when health checks fail. It collects system logs, failed units, and network state into a timestamped directory for debugging. ```bash #!/bin/bash DIAG_DIR="/var/log/greenboot-diagnostics/$(date +%Y%m%d-%H%M%S)" mkdir -p "$DIAG_DIR" journalctl -b > "$DIAG_DIR/journal.log" 2>&1 || true systemctl list-units --failed > "$DIAG_DIR/failed-units.log" 2>&1 || true dmesg > "$DIAG_DIR/dmesg.log" 2>&1 || true ss -tulpn > "$DIAG_DIR/network.log" 2>&1 || true echo "Diagnostics collected to $DIAG_DIR" ``` -------------------------------- ### Configure Greenboot Systemd Service Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt The systemd unit file for the Greenboot health checker. It runs as a oneshot service before boot-complete.target to validate system health. ```ini [Unit] Description=Greenboot Health Checks Runner Before=boot-complete.target OnFailureJobMode=fail RequiresMountsFor=/boot RequiresMountsFor=/etc RefuseManualStart=yes [Service] Type=oneshot RemainAfterExit=yes ExecStart=/usr/libexec/greenboot/greenboot health-check Restart=no PrivateMounts=yes [Install] RequiredBy=boot-complete.target WantedBy=multi-user.target ``` -------------------------------- ### Handle System Reboot and Rollback Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt System-level handlers to trigger reboots, perform rollbacks, and update the message of the day (MOTD). These functions automatically detect the underlying deployment system. ```rust use greenboot::{handle_reboot, handle_rollback, handle_motd, detect_os_deployment}; match detect_os_deployment() { Some("bootc") => println!("Running on bootc"), _ => (), } handle_reboot(false)?; handle_rollback()?; handle_motd("System status: OK")?; ``` -------------------------------- ### Create Wanted Health Check Script Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt A shell script template for non-critical health checks. Failures in wanted.d scripts are logged but do not initiate a system rollback. ```bash #!/bin/bash set -e if timedatectl show -p NTPSynchronized --value | grep -q "yes"; then echo "NTP is synchronized" exit 0 else echo "Warning: NTP is not synchronized" exit 1 fi ``` -------------------------------- ### Execute Health Check Scripts Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt Functions to trigger post-health-check scripts based on the success or failure of system checks. These functions return a list of errors encountered during script execution. ```rust use greenboot::{run_green, run_red}; let errors = run_green(); if !errors.is_empty() { for e in errors { eprintln!("Green script error: {}", e); } } let errors = run_red(); if !errors.is_empty() { for e in errors { eprintln!("Red script error: {}", e); } } ``` -------------------------------- ### Create Required Health Check Script Source: https://context7.com/fedora-iot/greenboot-rs/llms.txt A shell script template for critical health checks. Scripts placed in required.d that exit with a non-zero status will trigger a system rollback. ```bash #!/bin/bash set -e if ! pg_isready -h localhost -p 5432 -U postgres; then echo "PostgreSQL is not ready" exit 1 fi if ! psql -h localhost -U postgres -c "SELECT 1" >/dev/null 2>&1; then echo "Cannot connect to PostgreSQL" exit 1 fi echo "Database health check passed" exit 0 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.