Chapter 3. The greenboot health check framework
Learn about how greenboot health checks are used with MicroShift.
3.1. How greenboot uses directories to run scripts Copy linkLink copied to clipboard!
Greenboot is the generic health check framework for the systemd service on rpm-ostree systems such as Red Hat Enterprise Linux for Edge (RHEL for Edge). This framework is included in MicroShift installations with the microshift-greenboot and greenboot-default-health-checks RPM packages.
Greenboot health checks run at various times to assess system health and automate a rollback on rpm-ostree systems to the last healthy state in cases of software trouble, for example:
- Default health check scripts run each time the system starts.
- In addition the to the default health checks, you can write, install, and configure application health check scripts to also run every time the system starts.
- Greenboot can reduce your risk of being locked out of edge devices during updates and prevent a significant interruption of service if an update fails.
-
When a failure is detected, the system boots into the last known working configuration using the
rpm-ostreerollback capability. This feature is especially useful automation for edge devices where direct serviceability is either limited or non-existent.
A MicroShift application health check script is included in the microshift-greenboot RPM. The greenboot-default-health-checks RPM includes health check scripts verifying that DNS and ostree services are accessible. You can create your own health check scripts for the workloads you are running. You can write one that verifies that an application has started, for example.
3.2. How greenboot uses directories to run scripts Copy linkLink copied to clipboard!
Health check scripts run from four /etc/greenboot directories. These scripts run in alphabetical order. Keep this in mind when you configure the scripts for your workloads.
When the system starts, greenboot runs the scripts in the required.d and wanted.d directories. Depending on the outcome of those scripts, greenboot continues the startup or attempts a rollback as follows:
-
System as expected: When all of the scripts in the
required.ddirectory are successfully run, greenboot runs any scripts present in the/etc/greenboot/green.ddirectory. -
System trouble: If any of the scripts in the
required.ddirectory fail, greenboot runs any prerollback scripts present in thered.ddirectory, then restarts the system.
Greenboot redirects script and health check output to the system log. When you are logged in, a daily message provides the overall system health output.
3.2.1. Greenboot directories details Copy linkLink copied to clipboard!
Returning a nonzero exit code from any script means that script has failed. Greenboot restarts the system a few times to retry the scripts before attempting to roll back to the previous version.
/etc/greenboot/check/required.dcontains the health checks that must not fail.-
If the scripts fail, greenboot retries them three times by default. You can configure the number of retries in the
/etc/greenboot/greenboot.conffile by setting theGREENBOOT_MAX_BOOTSparameter to the desired number of retries. - After all retries fail, greenboot automatically initiates a rollback if one is available. If a rollback is not available, the system log output shows that manual intervention is required.
-
The
40_microshift_running_check.shhealth check script for MicroShift is installed into this directory.
-
If the scripts fail, greenboot retries them three times by default. You can configure the number of retries in the
/etc/greenboot/check/wanted.dcontains health scripts that are allowed to fail without causing the system to be rolled back.- If any of these scripts fail, greenboot logs the failure but does not initiate a rollback.
-
/etc/greenboot/green.dcontains scripts that run after greenboot has declared the start successful. -
/etc/greenboot/red.dcontains scripts that run after greenboot has declared the startup as failed, including the40_microshift_pre_rollback.shprerollback script. This script is executed right before a system rollback. The script performs MicroShift pod and OVN-Kubernetes cleanup to avoid potential conflicts after the system is rolled back to a previous version.
If you customize the values of any environment variable in the /etc/greenboot/greenboot.conf file, these changes can be lost when the greenboot RPM package is updated or downgraded.
-
To retain customizations when building system images with MicroShift, add the
greenboot.conffile to a blueprint. -
To retain customizations when using an RPM installation, apply changes to the
greenboot.conffile after you install MicroShift and greenboot RPMs.
3.3. Included greenboot health checks Copy linkLink copied to clipboard!
Health check scripts are available in /usr/lib/greenboot/check, a read-only directory in Red Hat Enterprise Linux for Edge (RHEL for Edge) image mode for RHEL systems. The following health checks are included with the greenboot-default-health-checks framework.
Check if repository URLs are still DNS solvable:
This script is under
/usr/lib/greenboot/check/required.d/01_repository_dns_check.shand ensures that DNS queries to repository URLs are still available.Check if update platforms are still reachable:
This script is under
/usr/lib/greenboot/check/wanted.d/01_update_platform_check.shand tries to connect and get a 2XX or 3XX HTTP code from the update platforms defined in/etc/ostree/remotes.d.Check if the current boot has been triggered by the hardware watchdog:
This script is under
/usr/lib/greenboot/check/required.d/02_watchdog.shand checks whether the current boot has been watchdog-triggered or not.- If the watchdog-triggered reboot occurs within the grace period, the current boot is marked as red. Greenboot does not trigger a rollback to the previous deployment.
- If the watchdog-triggered reboot occurs after the grace period, the current boot is not marked as red. Greenboot does not trigger a rollback to the previous deployment.
-
A 24-hour grace period is enabled by default. This grace period can be either disabled by modifying
GREENBOOT_WATCHDOG_CHECK_ENABLEDin/etc/greenboot/greenboot.conf to false, or configured by changing theGREENBOOT_WATCHDOG_GRACE_PERIOD=number_of_hoursvariable value in/etc/greenboot/greenboot.conf.
3.4. The MicroShift health check script Copy linkLink copied to clipboard!
The 40_microshift_running_check.sh health check script only performs validation of core MicroShift services. Install your customized workload health check scripts in the greenboot directories to ensure successful application operations after system updates. Scripts run in alphabetical order.
MicroShift health checks are listed in the following table:
| Validation | Pass | Fail |
|---|---|---|
|
Check that the script runs with | Next |
|
|
Check that the | Next |
|
|
Wait for the | Next |
|
| For each core namespace, wait for readiness of the workload | Next |
|
3.4.1. Validation wait period Copy linkLink copied to clipboard!
The wait period in each validation is 10 minutes by default. After the wait period, if the validation has not succeeded, it is declared a failure. This wait period is incrementally increased by the base wait period after each boot in the verification loop.
-
You can override the base-time wait period by setting the
MICROSHIFT_WAIT_TIMEOUT_SECenvironment variable in the/etc/greenboot/greenboot.confconfiguration file. For example, you can change the wait time to 5 minutes by resetting the value to 300 seconds, such asMICROSHIFT_WAIT_TIMEOUT_SEC=300.
3.5. Enabling systemd journal service data persistency Copy linkLink copied to clipboard!
The default configuration of the systemd journal service stores the data in the volatile /run/log/journal directory. To view system logs across system starts and restarts, you must enable log persistence and set limits on the maximal journal data size.
Procedure
Make the directory by running the following command:
$ sudo mkdir -p /etc/systemd/journald.conf.dCreate the configuration file by running the following command:
cat <<EOF | sudo tee /etc/systemd/journald.conf.d/microshift.conf &>/dev/null [Journal] Storage=persistent SystemMaxUse=1G RuntimeMaxUse=1G EOF- Edit the configuration file values for your size requirements.
3.6. Updates and third-party workloads Copy linkLink copied to clipboard!
Health checks are especially useful after an update. You can examine the output of greenboot health checks and determine whether the update was declared valid. This health check can help you determine if the system is working properly.
Health check scripts for updates are installed into the /etc/greenboot/check/required.d directory and are automatically executed during each system start. Exiting scripts with a nonzero status means the system start is declared as failed.
Wait until after an update is declared valid before starting third-party workloads. If a rollback is performed after workloads start, you can lose data. Some third-party workloads create or update data on a device before an update is complete. Upon rollback, the file system reverts to its state before the update.
3.7. Checking the results of an update Copy linkLink copied to clipboard!
After a successful start, greenboot sets the variable boot_success= to 1 in GRUB. You can view the overall status of system health checks after an update in the system log by using the following procedure.
Procedure
To access the overall status of system health checks, run the following command:
$ sudo grub2-editenv - list | grep ^boot_successExample output for a successful system start
boot_success=11 - 1
- If your command returns
boot_success=0, either the greenboot health check is still running, or the update is a failure.
3.8. Accessing health check output in the system log Copy linkLink copied to clipboard!
You can manually access the output of health checks in the system log by using the following procedure.
Procedure
To access the results of a health check, run the following command:
$ sudo journalctl -o cat -u greenboot-healthcheck.serviceExample output of a failed health check
... ... Running Required Health Check Scripts... STARTED GRUB boot variables: boot_success=0 boot_indeterminate=0 boot_counter=2 ... ... Waiting 600s for MicroShift service to be active and not failed FAILURE ... ...
3.9. Accessing prerollback health check output in the system log Copy linkLink copied to clipboard!
You can access the output of health check scripts in the system log. For example, check the results of a pre-rollback script using the following procedure.
Procedure
To access the results of a prerollback script, run the following command:
$ sudo journalctl -o cat -u redboot-task-runner.serviceExample output of a prerollback script
... ... Running Red Scripts... STARTED GRUB boot variables: boot_success=0 boot_indeterminate=0 boot_counter=0 The ostree status: * rhel c0baa75d9b585f3dd989a9cf05f647eb7ca27ee0dbd4b94fe8c93ed3a4b9e4a5.0 Version: 9.6 origin: <unknown origin type> rhel 6869c1347b0e0ba1bbf0be750cdf32da5138a1fcbc5a4c6325ab9eb647b64663.0 (rollback) Version: 9.6 origin refspec: edge:rhel/9/x86_64/edge System rollback imminent - preparing MicroShift for a clean start Stopping MicroShift services Removing MicroShift pods Killing conmon, pause and OVN processes Removing OVN configuration Finished greenboot Failure Scripts Runner. Cleanup succeeded Script '40_microshift_pre_rollback.sh' SUCCESS FINISHED redboot-task-runner.service: Deactivated successfully.NoteIn case of a rollback, the pre-rollback script runs the
sudo microshift-cleanup-data --ovncommand to prepare the system for a potential software downgrade.
3.10. Checking updates with a health check script Copy linkLink copied to clipboard!
Access the output of greenboot health check scripts in the system log after an update by using the following procedure.
Procedure
To access the result of update checks, run the following command:
$ sudo grub2-editenv - list | grep ^boot_successExample output for a successful update
boot_success=11 - 1
- If your command returns
boot_success=0, either the greenboot health check is still running, or the update is a failure.