Skip to content

Commit 984147d

Browse files
committed
Update to v0.6
1 parent 62fef66 commit 984147d

File tree

8 files changed

+164
-89
lines changed

8 files changed

+164
-89
lines changed

README.md

+36-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,26 @@
11
# greenboot
22
Generic Health Check Framework for systemd
33

4+
## Installation
5+
On Fedora Silverblue, IoT or Atomic Host:
6+
```
7+
rpm-ostree install greenboot greenboot-status greenboot-ostree-grub2
8+
9+
systemctl reboot
10+
```
11+
412
## Usage
5-
The following directory structure is created:
13+
Place shell scripts representing *health checks* that **MUST NOT FAIL** in the `/etc/greenboot/check/required.d` directory.
14+
Place shell scripts representing *health checks* that **MAY FAIL** in the `/etc/greenboot/check/wanted.d` directory.
15+
Place shell scripts you want to run *after* a boot has been declared **successful** in `/etc/greenboot/green.d`.
16+
Place shell scripts you want to run *after* a boot has been declared **failed** in `/etc/greenboot/red.d`.
617

18+
Unless greenboot is enabled by default in your distribution, enable it by running `systemctl enable greenboot greenboot-healthcheck greenboot-status`.
19+
It will automatically start during the next boot process and run its checks.
20+
21+
When you `ssh` into the machine after that, a boot status message will be shown.
22+
23+
Directory structure:
724
```
825
/etc
926
└── greenboot
@@ -14,40 +31,39 @@ The following directory structure is created:
1431
└── red.d
1532
```
1633

17-
### Custom Health Checks
18-
You have multiple options to customize greenboot’s health checking behaviour:
1934

20-
* Drop scripts representing health checks that MUST NOT FAIL in order to reach a GREEN boot status into `/etc/greenboot/check/required.d`.
21-
* Drop scripts representing health checks that MAY FAIL into `/etc/greenboot/check/wanted.d`.
22-
* Create oneshot health check service units that MUST NOT FAIL like the following and drop them into `/etc/systemd/system` (don't forget to `systemctl enable` them afterwards):
35+
## Health Checks with systemd services
36+
Overall boot success is measured against `boot-success.target`.
37+
Ordering of units can be achieved using standard systemd vocabulary.
38+
39+
### Required Checks
40+
Create a oneshot health check service unit that **MUST NOT FAIL**, e.g. `/etc/systemd/system/required-check.service`. Run `systemctl enable required-check` to enable it.
41+
2342
```
2443
[Unit]
2544
Description=Custom Required Health Check
26-
Before=greenboot.target
45+
Before=boot-complete.target
2746
2847
[Service]
2948
Type=oneshot
30-
ExecStart=/path/to/service
49+
ExecStart=/usr/libexec/mytestsuite/required-check
3150
3251
[Install]
33-
RequiredBy=greenboot.target
52+
RequiredBy=boot-complete.target
3453
```
35-
* Create oneshot health check service units that MAY FAIL like the following and drop them into `/etc/systemd/system` (don't forget to `systemctl enable` them afterwards):
54+
55+
### Wanted Checks
56+
Create a oneshot health check service unit that **MAY FAIL**, e.g. `/etc/systemd/system/wanted-check.service`. Run `systemctl enable wanted-check` to enable it.
57+
3658
```
3759
[Unit]
3860
Description=Custom Wanted Health Check
39-
Before=greenboot.target
61+
Before=boot-complete.target
4062
4163
[Service]
4264
Type=oneshot
43-
ExecStart=/path/to/service
65+
ExecStart=/usr/libexec/mytestsuite/wanted-check
4466
4567
[Install]
46-
WantedBy=greenboot.target
47-
```
48-
49-
### Custom GREEN Status Procedures
50-
* Drop scripts representing procedures you want to run after a GREEN boot status has been reached into `/etc/greenboot/green.d`.
51-
52-
### Custom RED Status Procedures
53-
* Drop scripts representing procedures you want to run after a RED boot status has been reached into `/etc/greenboot/red.d`.
68+
RequiredBy=boot-complete.target
69+
```

greenboot.spec

+39-35
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
1-
%global github_owner LorbusChris
2-
%global github_project greenboot
3-
%global build_timestamp %(date +"%Y%m%d%H%M%%S")
4-
51
Name: greenboot
6-
Version: 0.5
2+
Version: 0.6
73
Release: 1%{?dist}
84
Summary: Generic Health Check Framework for systemd
95
License: LGPLv2+
10-
URL: https://github.com/%{github_owner}/%{github_project}
11-
Source0: https://github.com/%{github_owner}/%{github_project}/archive/v%{version}.tar.gz
6+
7+
%global repo_owner LorbusChris
8+
%global repo_name %{name}
9+
%global repo_tag v%{version}
10+
11+
URL: https://github.com/%{repo_owner}/%{repo_name}
12+
Source0: https://github.com/%{repo_owner}/%{repo_name}/archive/%{repo_tag}.tar.gz
1213

1314
BuildArch: noarch
14-
BuildRequires: systemd
15+
BuildRequires: systemd-rpm-macros
1516
%{?systemd_requires}
1617
Requires: systemd
1718

1819
%description
1920
%{summary}.
2021

21-
%package motd
22+
%package status
2223
Summary: Message of the Day updater for greenboot
2324
Requires: %{name} = %{version}-%{release}
24-
Requires: pam >= 1.3.1
25+
Requires: pam >= 1.3.1-15
2526
Requires: openssh
2627

27-
%description motd
28+
%description status
2829
%{summary}.
2930

3031
%package ostree-grub2
@@ -51,54 +52,50 @@ Requires: %{name} = %{version}-%{release}
5152
%{summary}.
5253

5354
%prep
54-
%setup -qn %{github_project}-%{version}
55+
%setup
5556

5657
%build
5758

5859
%install
59-
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
61-
install -Dpm 0644 usr/lib/systemd/system/greenboot.target %{buildroot}%{_unitdir}/greenboot.target
62-
install -Dpm 0644 usr/lib/systemd/system/greenboot-healthcheck.service %{buildroot}%{_unitdir}/greenboot-healthcheck.service
63-
install -Dpm 0644 usr/lib/systemd/system/greenboot.service %{buildroot}%{_unitdir}/greenboot.service
64-
install -Dpm 0644 usr/lib/systemd/system/redboot.service %{buildroot}%{_unitdir}/redboot.service
65-
install -Dpm 0644 usr/lib/systemd/system/greenboot-motdgen.service %{buildroot}%{_unitdir}/greenboot-motdgen.service
6660
mkdir -p %{buildroot}%{_sysconfdir}/%{name}/check/required.d
6761
mkdir %{buildroot}%{_sysconfdir}/%{name}/check/wanted.d
6862
mkdir %{buildroot}%{_sysconfdir}/%{name}/green.d
6963
mkdir %{buildroot}%{_sysconfdir}/%{name}/red.d
64+
install -Dpm 0755 usr/libexec/greenboot/greenboot %{buildroot}%{_libexecdir}/%{name}/%{name}
65+
install -Dpm 0755 usr/libexec/greenboot/greenboot-status %{buildroot}%{_libexecdir}/%{name}/greenboot-status
66+
install -Dpm 0644 usr/lib/motd.d/boot-status %{buildroot}%{_exec_prefix}/lib/motd.d/boot-status
67+
install -Dpm 0644 usr/lib/systemd/system/greenboot-healthcheck.service %{buildroot}%{_unitdir}/greenboot-healthcheck.service
68+
install -Dpm 0644 usr/lib/systemd/system/greenboot.service %{buildroot}%{_unitdir}/greenboot.service
69+
install -Dpm 0644 usr/lib/systemd/system/redboot.service %{buildroot}%{_unitdir}/redboot.service
70+
install -Dpm 0644 usr/lib/systemd/system/greenboot-status.service %{buildroot}%{_unitdir}/greenboot-status.service
7071
install -Dpm 0755 etc/greenboot/check/required.d/* %{buildroot}%{_sysconfdir}/%{name}/check/required.d
7172
install -Dpm 0755 etc/greenboot/check/wanted.d/* %{buildroot}%{_sysconfdir}/%{name}/check/wanted.d
7273
install -Dpm 0755 etc/greenboot/green.d/* %{buildroot}%{_sysconfdir}/%{name}/green.d
7374
install -Dpm 0755 etc/greenboot/red.d/* %{buildroot}%{_sysconfdir}/%{name}/red.d
74-
install -Dpm 0644 etc/greenboot/motd %{buildroot}%{_sysconfdir}/%{name}/motd
7575

7676
%post
77-
%systemd_post greenboot.target
7877
%systemd_post greenboot.service
7978
%systemd_post greenboot-healthcheck.service
8079
%systemd_post redboot.service
8180

82-
%post motd
83-
%systemd_post greenboot-motdgen.service
81+
%post status
82+
%systemd_post greenboot-status.service
8483

8584
%preun
86-
%systemd_preun greenboot.target
8785
%systemd_preun greenboot.service
8886
%systemd_preun greenboot-healthcheck.service
8987
%systemd_preun redboot.service
9088

91-
%preun motd
92-
%systemd_preun greenboot-motdgen.service
89+
%preun status
90+
%systemd_preun greenboot-status.service
9391

9492
%postun
95-
%systemd_postun_with_restart greenboot.target
9693
%systemd_postun_with_restart greenboot.service
9794
%systemd_postun_with_restart greenboot-healthcheck.service
9895
%systemd_postun_with_restart redboot.service
9996

100-
%postun motd
101-
%systemd_postun greenboot-motdgen.service
97+
%postun status
98+
%systemd_postun greenboot-status.service
10299

103100
%check
104101
# TODO
@@ -107,8 +104,7 @@ install -Dpm 0644 etc/greenboot/motd %{buildroot}%{_sysconfdir}/%{name}/motd
107104
%doc README.md
108105
%license LICENSE
109106
%dir %{_libexecdir}/%{name}
110-
%{_libexecdir}/%{name}/%{name}.sh
111-
%{_unitdir}/greenboot.target
107+
%{_libexecdir}/%{name}/%{name}
112108
%{_unitdir}/greenboot-healthcheck.service
113109
%{_unitdir}/greenboot.service
114110
%{_unitdir}/redboot.service
@@ -121,10 +117,10 @@ install -Dpm 0644 etc/greenboot/motd %{buildroot}%{_sysconfdir}/%{name}/motd
121117
%dir %{_sysconfdir}/%{name}/green.d
122118
%dir %{_sysconfdir}/%{name}/red.d
123119

124-
%files motd
125-
%config %{_sysconfdir}/%{name}/motd
126-
%{_libexecdir}/%{name}/%{name}_motdgen.sh
127-
%{_unitdir}/greenboot-motdgen.service
120+
%files status
121+
%{_exec_prefix}/lib/motd.d/boot-status
122+
%{_libexecdir}/%{name}/greenboot-status
123+
%{_unitdir}/greenboot-status.service
128124

129125
%files ostree-grub2
130126
%{_sysconfdir}/%{name}/green.d/01_ostree_grub2_fallback.sh
@@ -136,6 +132,14 @@ install -Dpm 0644 etc/greenboot/motd %{buildroot}%{_sysconfdir}/%{name}/motd
136132
%{_sysconfdir}/%{name}/red.d/99_reboot.sh
137133

138134
%changelog
135+
* Wed Feb 13 2019 Christian Glombek <[email protected]> - 0.6-1
136+
- Update to v0.6
137+
- Integrate with systemd's boot-complete.target
138+
- Rewrite motd sub-package and rename to status
139+
140+
* Fri Oct 19 2018 Christian Glombek <[email protected]> - 0.5-1
141+
- Update to v0.5
142+
139143
* Tue Oct 02 2018 Christian Glombek <[email protected]> - 0.4-2
140144
- Spec Review
141145

tests/atomic/Vagrantfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Vagrant.configure(2) do |config|
3434

3535
config.vm.provision "shell", inline: <<-SHELL
3636
curl https://copr.fedorainfracloud.org/coprs/lorbus/greenboot/repo/fedora-rawhide/lorbus-greenboot-fedora-rahide.repo --output /etc/yum.repos.d/_copr_lorbus-greenboot.repo
37-
rpm-ostree install greenboot greenboot-motd greenboot-ostree-grub2
38-
systemctl reboot
37+
rpm-ostree install greenboot greenboot-status greenboot-ostree-grub2
38+
echo "rebooting..." && systemctl reboot
3939
SHELL
4040

4141
end

tests/fedora/Vagrantfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ Vagrant.configure(2) do |config|
3434

3535
config.vm.provision "shell", inline: <<-SHELL
3636
curl https://copr.fedorainfracloud.org/coprs/lorbus/greenboot/repo/fedora-rawhide/lorbus-greenboot-fedora-rahide.repo --output /etc/yum.repos.d/_copr_lorbus-greenboot.repo
37-
dnf install -y greenboot greenboot-motd greenboot-reboot
38-
systemctl reboot
37+
dnf install -y greenboot greenboot-status greenboot-reboot
38+
echo "rebooting" && systemctl reboot
3939
SHELL
4040

4141
end

tests/greenboot-failing-unit.spec

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Name: greenboot-failing-unit
2+
Version: 1.0
3+
Release: 1%{?dist}
4+
Summary: Failing healthcheck unit for testing greenboot red status
5+
License: LGPLv2+
6+
URL: https://github.com/%{repo_owner}/%{repo_name}
7+
BuildArch: noarch
8+
Requires: greenboot
9+
10+
%description
11+
%{summary}.
12+
13+
%prep
14+
15+
%build
16+
17+
%install
18+
mkdir -p %{buildroot}%{_sysconfdir}/greenboot/check/required.d/
19+
cat <<EOF > %{buildroot}%{_sysconfdir}/greenboot/check/required.d/10_failing_check.sh
20+
#!/bin/bash
21+
set -euo pipefail
22+
echo "This is a failing script"
23+
exit 1
24+
EOF
25+
26+
%post
27+
28+
%preun
29+
30+
%postun
31+
32+
%files
33+
%{_sysconfdir}/greenboot/check/required.d/10_failing_check.sh
34+
35+
%changelog
36+
* Wed Feb 13 2019 Christian Glombek <[email protected]> - 1.0-1
37+
- Initial RPM Spec

tests/run_test.sh

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
14
## Set up vagrant-libvirt
25
# getent group libvirt
36
# groups ${USER}
@@ -6,25 +9,34 @@
69
## Fix for Silverblue
710
# sudo restorecon -Rv /etc/libvirt # -> Relabeled /etc/libvirt from system_u:object_r:virt_etc_rw_t:s0 to system_u:object_r:virt_etc_t:s0
811

12+
## TODO: Convert into Ansible Playbook; this can't really be run as a script
13+
914
cd atomic
1015

1116
vagrant up
12-
# Use the failing check to test red boot status behaviour
13-
# vagrant ssh -c 'ln -s /home/vagrant/sync/10_failing_check.sh /etc/greenboot/check/required.d/10_failing_check.sh'
1417

15-
# Workaround for https://github.com/fedora-selinux/selinux-policy/issues/242
16-
vagrant ssh -c 'sudo semanage fcontext -a -t pam_var_run_t "/var/run/motd.d(/.*)?"; \
17-
sudo restorecon -Rv /var/run/motd.d;'
18+
# v0.7: Workaround for https://github.com/fedora-selinux/selinux-policy/issues/242
19+
# vagrant ssh -c 'sudo semanage fcontext -a -t pam_var_run_t "/var/run/motd\.d(/.*)?"; \
20+
# sudo restorecon -Rv /var/run/motd.d;'
1821

19-
vagrant ssh -c 'sudo systemctl enable greenboot greenboot-healthcheck bootstatus-motd; \
20-
sudo systemctl reboot;'
22+
vagrant ssh -c 'sudo systemctl enable greenboot greenboot-healthcheck greenboot-status; \
23+
echo "rebooting..." && sudo systemctl reboot;'
2124
sleep 15
2225

23-
vagrant ssh -c 'sudo journalctl -u greenboot-healthcheck -u boot-complete.target -u greenboot -u redboot -u bootstatus-motd'
26+
vagrant ssh -c 'sudo journalctl -u greenboot-healthcheck -u boot-complete.target -u greenboot -u redboot -u greenboot-status'
27+
28+
# Check Green Status MotD
29+
# vagrant ssh
30+
31+
vagrant ssh -c 'sudo rpm-ostree cleanup -m; \
32+
sudo rpm-ostree install greenboot-failing-unit; \
33+
sudo grub2-editenv - set boot_success=0; \
34+
sudo grub2-editenv - set boot_counter=1; \
35+
echo "rebooting..." && sudo systemctl reboot;'
36+
37+
vagrant ssh -c 'sudo journalctl -u greenboot-healthcheck -u boot-complete.target -u greenboot -u redboot -u greenboot-status'
2438

25-
# vagrant ssh -c 'sudo rpm-ostree upgrade; \
26-
# sudo grub2-editenv - set boot_success=0; \
27-
# sudo grub2-editenv - set boot_counter=3; \
28-
# sudo systemctl reboot;'
39+
# Check Red Status MotD
40+
# vagrant ssh
2941

3042
cd ..

usr/libexec/greenboot/greenboot

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ script_runner () {
77
local mode=$1; shift
88
local start_msg=$1; shift
99
echo "$start_msg"
10-
for script in `find $scripts_dir -name '*.sh'`; do
10+
for script in $(find $scripts_dir -name '*.sh'); do
1111
local rc=0
1212
systemd-cat -t "$(basename $script)" bash $script || rc=$?
1313
if [ $rc -ne 0 ]; then

0 commit comments

Comments
 (0)