Skip to content

Commit

Permalink
Merge pull request #179 from cgwalters/add-systemd-auto
Browse files Browse the repository at this point in the history
  systemd: New bootc-fetch-apply-updates.{timer,service}
  • Loading branch information
rhatdan authored Jan 17, 2024
2 parents 0910876 + c13c9eb commit d720fdd
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ all-test:
install:
install -D -m 0755 -t $(DESTDIR)$(prefix)/bin target/release/bootc
install -d $(DESTDIR)$(prefix)/lib/bootc/install
# Support installing pre-generated man pages shipped in source tarball, to avoid
# a dependency on pandoc downstream
if test -d man; then install -D -m 0644 -t $(DESTDIR)$(prefix)/share/man/man5 man/*.5; fi
if test -d man; then install -D -m 0644 -t $(DESTDIR)$(prefix)/share/man/man8 man/*.8; fi

# These are not installed by default; one recommendation is to put them in a separate
# sub-package or sub-component.
install-systemd-auto:
install -D -m 0644 -t $(DESTDIR)/$(prefix)/lib/systemd/system systemd/*.service systemd/*.timer

bin-archive: all
$(MAKE) install DESTDIR=tmp-install && tar --zstd -C tmp-install -cf target/bootc.tar.zst . && rm tmp-install -rf

Expand Down
27 changes: 27 additions & 0 deletions manpages-md-extra/bootc-fetch-apply-updates.service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# NAME

bootc-fetch-apply-updates.service

# DESCRIPTION

This service causes `bootc` to perform the following steps:

- Check the source registry for an updated container image
- If one is found, download it
- Reboot

This service also comes with a companion `bootc-fetch-apply-updates.timer`
systemd unit. The current default systemd timer shipped in the upstream
project is enabled for daily updates.

However, it is fully expected that different operating systems
and distributions choose different defaults.

## Customizing updates

Note that all three of these steps can be decoupled; they
are:

- `bootc upgrade --check`
- `bootc upgrade`
- `bootc upgrade --apply`
8 changes: 8 additions & 0 deletions systemd/bootc-fetch-apply-updates.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Apply bootc updates
Documentation=man:bootc(8)
ConditionPathExists=/run/ostree-booted

[Service]
Type=oneshot
ExecStart=/usr/bin/bootc update --apply --quiet
12 changes: 12 additions & 0 deletions systemd/bootc-fetch-apply-updates.timer
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Apply bootc updates
Documentation=man:bootc(8)
ConditionPathExists=/run/ostree-booted

[Timer]
OnBootSec=1h
# This time is relatively arbitrary and obviously expected to be overridden/changed
OnUnitInactiveSec=8h

[Install]
WantedBy=timers.target
25 changes: 25 additions & 0 deletions xtask/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,37 @@ fn gitrev(sh: &Shell) -> Result<String> {

#[context("Manpages")]
fn manpages(sh: &Shell) -> Result<()> {
// We currently go: clap (Rust) -> man -> markdown for the CLI
sh.create_dir("target/man")?;
cmd!(
sh,
"cargo run --features=docgen -- man --directory target/man"
)
.run()?;
// We also have some man pages for the systemd units which are canonically
// maintained as markdown; convert them to man pages.
let extradir = sh.current_dir().join("manpages-md-extra");
for ent in std::fs::read_dir(extradir)? {
let ent = ent?;
let srcpath = ent.path();
let extension = if let Some(extension) = srcpath.extension() {
extension
} else {
continue;
};
if extension != "md" {
continue;
}
let base_filename = srcpath
.file_stem()
.and_then(|name| name.to_str())
.ok_or_else(|| anyhow!("Expected filename in {srcpath:?}"))?;
cmd!(
sh,
"pandoc --from=markdown --to=man --output=target/man/{base_filename}.5 {srcpath}"
)
.run()?;
}
Ok(())
}

Expand Down

0 comments on commit d720fdd

Please sign in to comment.