Skip to content

Commit cf8b14a

Browse files
authored
Merge pull request #21 from LorbusChris/dev
Update to v0.6
2 parents aa076be + 984147d commit cf8b14a

19 files changed

+297
-134
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
tests/.vagrant
1+
**/.vagrant

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+
```

etc/greenboot/motd

-1
This file was deleted.

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/Vagrantfile

-25
This file was deleted.

tests/atomic/Vagrantfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrant Rawhide Atomic Box
5+
Vagrant.configure(2) do |config|
6+
7+
config.ssh.insert_key = 'true'
8+
# config.ssh.forward_agent = 'true'
9+
10+
config.vm.provider :libvirt do |domain|
11+
domain.memory = 1024
12+
end
13+
14+
host = 'vanilla-rawhide-atomic'
15+
box = 'fedora/rawhide-atomic-host'
16+
17+
# Grab latest successful compose ID
18+
require 'open-uri'
19+
uri = URI.parse("https://kojipkgs.fedoraproject.org/compose/rawhide/latest-Fedora-Rawhide/COMPOSE_ID")
20+
id = uri.read
21+
# Grab the date type respin string from that
22+
datetyperespin = /(\d{8}\.n\.\d)/.match(id)[0]
23+
24+
# Derive the box url from those two
25+
box_url = "https://kojipkgs.fedoraproject.org/compose/rawhide/#{id}/compose/AtomicHost/x86_64/images/Fedora-AtomicHost-Vagrant-Rawhide-#{datetyperespin}.x86_64.vagrant-libvirt.box"
26+
box = "rawhide-atomic-host-#{datetyperespin}"
27+
28+
config.vm.define host do | tmp |
29+
tmp.vm.hostname = host
30+
tmp.vm.box = box
31+
tmp.vm.box_url = box_url
32+
# tmp.vm.box_version = version
33+
end
34+
35+
config.vm.provision "shell", inline: <<-SHELL
36+
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-status greenboot-ostree-grub2
38+
echo "rebooting..." && systemctl reboot
39+
SHELL
40+
41+
end

tests/fedora/Vagrantfile

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# Vagrant Rawhide Box
5+
Vagrant.configure(2) do |config|
6+
7+
config.ssh.insert_key = 'true'
8+
# config.ssh.forward_agent = 'true'
9+
10+
config.vm.provider :libvirt do |domain|
11+
domain.memory = 1024
12+
end
13+
14+
host = 'vanilla-rawhide'
15+
box = 'fedora/rawhide-cloud-base'
16+
17+
# Grab latest successful compose ID
18+
require 'open-uri'
19+
uri = URI.parse("https://kojipkgs.fedoraproject.org/compose/rawhide/latest-Fedora-Rawhide/COMPOSE_ID")
20+
id = uri.read
21+
# Grab the date type respin string from that
22+
datetyperespin = /(\d{8}\.n\.\d)/.match(id)[0]
23+
24+
# Derive the box url from those two
25+
box_url = "https://kojipkgs.fedoraproject.org/compose/rawhide/#{id}/compose/Cloud/x86_64/images/Fedora-Cloud-Base-Vagrant-Rawhide-#{datetyperespin}.x86_64.vagrant-libvirt.box"
26+
box = "rawhide-cloud-base-#{datetyperespin}"
27+
28+
config.vm.define host do | tmp |
29+
tmp.vm.hostname = host
30+
tmp.vm.box = box
31+
tmp.vm.box_url = box_url
32+
# tmp.vm.box_version = version
33+
end
34+
35+
config.vm.provision "shell", inline: <<-SHELL
36+
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-status greenboot-reboot
38+
echo "rebooting" && systemctl reboot
39+
SHELL
40+
41+
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_ostree_upgrade.sh

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ rpm-ostree upgrade
55
# In order to activate grub2's Boot Couting feature,
66
# boot_counter must be set to a number >= 1, and boot_success=0
77
grub2-editenv - set boot_success=0
8+
# set initial counter (maxCount)
89
grub2-editenv - set boot_counter=3
910
reboot

0 commit comments

Comments
 (0)