Skip to content

Commit aa076be

Browse files
authored
Merge pull request #18 from LorbusChris/dev
Dynamic greenboot MotD
2 parents 6cc3b78 + a7be271 commit aa076be

13 files changed

+60
-35
lines changed

etc/greenboot/green.d/00_greenboot_notification.sh

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22
set -euo pipefail
33

4-
# We need to determine whether this boot was a fallback boot
4+
# Determine if the current boot is a fallback boot
55
if grub2-editenv list | grep -q "^boot_counter=-1$"; then
6+
# If booted into fallback deployment, clean up bootloader entries (rollback)
67
rpm-ostree rollback
78
fi

etc/greenboot/green.d/50_greenboot_motd.sh

-4
This file was deleted.

etc/greenboot/motd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
greenboot hasn't run, yet. Boot Status is INDETERMINATE.

etc/greenboot/motd/greenboot.motd

-1
This file was deleted.

etc/greenboot/motd/redboot.motd

-2
This file was deleted.

etc/greenboot/red.d/00_redboot_notification.sh

-4
This file was deleted.

etc/greenboot/red.d/50_redboot_motd.sh

-4
This file was deleted.

greenboot.spec

+17-14
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
%global build_timestamp %(date +"%Y%m%d%H%M%%S")
44

55
Name: greenboot
6-
Version: 0.4
7-
Release: 2%{?dist}
6+
Version: 0.5
7+
Release: 1%{?dist}
88
Summary: Generic Health Check Framework for systemd
99
License: LGPLv2+
1010
URL: https://github.com/%{github_owner}/%{github_project}
@@ -57,42 +57,49 @@ Requires: %{name} = %{version}-%{release}
5757

5858
%install
5959
install -Dpm 0755 usr/libexec/greenboot/greenboot.sh %{buildroot}%{_libexecdir}/%{name}/%{name}.sh
60+
install -Dpm 0755 usr/libexec/greenboot/greenboot_motdgen.sh %{buildroot}%{_libexecdir}/%{name}/%{name}_motdgen.sh
6061
install -Dpm 0644 usr/lib/systemd/system/greenboot.target %{buildroot}%{_unitdir}/greenboot.target
6162
install -Dpm 0644 usr/lib/systemd/system/greenboot-healthcheck.service %{buildroot}%{_unitdir}/greenboot-healthcheck.service
6263
install -Dpm 0644 usr/lib/systemd/system/greenboot.service %{buildroot}%{_unitdir}/greenboot.service
6364
install -Dpm 0644 usr/lib/systemd/system/redboot.service %{buildroot}%{_unitdir}/redboot.service
64-
mkdir -p %{buildroot}/run/%{name}
65-
mkdir -p %{buildroot}%{_sysconfdir}/motd.d
65+
install -Dpm 0644 usr/lib/systemd/system/greenboot-motdgen.service %{buildroot}%{_unitdir}/greenboot-motdgen.service
6666
mkdir -p %{buildroot}%{_sysconfdir}/%{name}/check/required.d
6767
mkdir %{buildroot}%{_sysconfdir}/%{name}/check/wanted.d
6868
mkdir %{buildroot}%{_sysconfdir}/%{name}/green.d
6969
mkdir %{buildroot}%{_sysconfdir}/%{name}/red.d
70-
mkdir %{buildroot}%{_sysconfdir}/%{name}/motd
7170
install -Dpm 0755 etc/greenboot/check/required.d/* %{buildroot}%{_sysconfdir}/%{name}/check/required.d
7271
install -Dpm 0755 etc/greenboot/check/wanted.d/* %{buildroot}%{_sysconfdir}/%{name}/check/wanted.d
7372
install -Dpm 0755 etc/greenboot/green.d/* %{buildroot}%{_sysconfdir}/%{name}/green.d
7473
install -Dpm 0755 etc/greenboot/red.d/* %{buildroot}%{_sysconfdir}/%{name}/red.d
75-
install -Dpm 0644 etc/greenboot/motd/* %{buildroot}%{_sysconfdir}/%{name}/motd
76-
ln -snf /run/greenboot/motd %{buildroot}%{_sysconfdir}/motd.d/%{name}
74+
install -Dpm 0644 etc/greenboot/motd %{buildroot}%{_sysconfdir}/%{name}/motd
7775

7876
%post
7977
%systemd_post greenboot.target
8078
%systemd_post greenboot.service
8179
%systemd_post greenboot-healthcheck.service
8280
%systemd_post redboot.service
8381

82+
%post motd
83+
%systemd_post greenboot-motdgen.service
84+
8485
%preun
8586
%systemd_preun greenboot.target
8687
%systemd_preun greenboot.service
8788
%systemd_preun greenboot-healthcheck.service
8889
%systemd_preun redboot.service
8990

91+
%preun motd
92+
%systemd_preun greenboot-motdgen.service
93+
9094
%postun
9195
%systemd_postun_with_restart greenboot.target
9296
%systemd_postun_with_restart greenboot.service
9397
%systemd_postun_with_restart greenboot-healthcheck.service
9498
%systemd_postun_with_restart redboot.service
9599

100+
%postun motd
101+
%systemd_postun greenboot-motdgen.service
102+
96103
%check
97104
# TODO
98105

@@ -112,16 +119,12 @@ ln -snf /run/greenboot/motd %{buildroot}%{_sysconfdir}/motd.d/%{name}
112119
%dir %{_sysconfdir}/%{name}/check/wanted.d
113120
%{_sysconfdir}/%{name}/check/wanted.d/00_wanted_scripts_start.sh
114121
%dir %{_sysconfdir}/%{name}/green.d
115-
%{_sysconfdir}/%{name}/green.d/00_greenboot_notification.sh
116122
%dir %{_sysconfdir}/%{name}/red.d
117-
%{_sysconfdir}/%{name}/red.d/00_redboot_notification.sh
118123

119124
%files motd
120-
%dir /run/%{name}
121-
%config(noreplace) %{_sysconfdir}/motd.d/%{name}
122-
%config %{_sysconfdir}/%{name}/motd/
123-
%{_sysconfdir}/%{name}/green.d/50_greenboot_motd.sh
124-
%{_sysconfdir}/%{name}/red.d/50_redboot_motd.sh
125+
%config %{_sysconfdir}/%{name}/motd
126+
%{_libexecdir}/%{name}/%{name}_motdgen.sh
127+
%{_unitdir}/greenboot-motdgen.service
125128

126129
%files ostree-grub2
127130
%{_sysconfdir}/%{name}/green.d/01_ostree_grub2_fallback.sh

tests/run_ostree_upgrade.sh

100644100755
+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
set -euo pipefail
33

44
rpm-ostree upgrade
5+
# In order to activate grub2's Boot Couting feature,
6+
# boot_counter must be set to a number >= 1, and boot_success=0
57
grub2-editenv - set boot_success=0
68
grub2-editenv - set boot_counter=3
79
reboot
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Unit]
2+
Description=greenboot MotD Generator
3+
After=greenboot-healthcheck.service
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/usr/libexec/greenboot/greenboot_motdgen.sh
8+
9+
[Install]
10+
WantedBy=greenboot.service redboot.service

usr/libexec/greenboot/greenboot.sh

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ script_runner () {
2121
exit $rc
2222
esac
2323
else
24-
echo "<5>Script '$(basename $script)' SUCCESS"
24+
echo "<6>Script '$(basename $script)' SUCCESS"
2525
fi
2626
done
2727
}
@@ -32,9 +32,11 @@ case "$1" in
3232
script_runner "/etc/greenboot/check/wanted.d" "relaxed" "Running Wanted Health Check Scripts..."
3333
;;
3434
"green")
35+
echo "<5>Boot Status is GREEN - Health Check SUCCESS!"
3536
script_runner "/etc/greenboot/green.d" "relaxed" "Running Green Scripts..."
3637
;;
3738
"red")
39+
echo "<0>Boot Status is RED - Health Check FAILURE!"
3840
script_runner "/etc/greenboot/red.d" "relaxed" "Running Red Scripts..."
3941
;;
4042
*)
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
if [ ! -d /etc/motd.d ]; then
5+
mkdir /etc/motd.d
6+
fi
7+
8+
if [ "$(systemctl is-active greenboot.target)" = "active" ]; then
9+
greenboot_logs=$(journalctl -u greenboot.service -p 0..5 -b -0 -o cat)
10+
printf '%s\n' "$greenboot_logs" > /etc/greenboot/motd
11+
else
12+
redboot_logs=$(journalctl -u redboot.service -p 0..5 -b -0 -o cat)
13+
printf '%s\n' "$redboot_logs" > /etc/greenboot/motd
14+
current_healthcheck_logs=$(journalctl -u greenboot-healthcheck.service -p 0..2 -b 0 -o cat)
15+
printf '%\n' "$current_healthcheck_logs" >> /etc/greenboot/motd
16+
fi
17+
18+
if grub2-editenv list | grep -q "^boot_counter=-1$"; then
19+
prev_healthcheck_logs=$(journalctl -u greenboot-healthcheck.service -p 0..2 -b -1 -o cat)
20+
printf 'The current boot seems to be a fallback boot. Showing health check logs from previous boot:\n%s\n' "$prev_healthcheck_logs" >> /etc/greenboot/motd
21+
fi
22+
23+
# remove the following line and write above directly to /run/motd.d/greenboot
24+
# once https://github.com/linux-pam/linux-pam/pull/69 is merged
25+
ln -snf /etc/greenboot/motd /etc/motd.d/greenboot

0 commit comments

Comments
 (0)