Skip to content

feat(daemon): ship the update timer and service in the package - #459

Merged
bketelsen merged 10 commits into
mainfrom
feat/packaged-update-units
Oct 24, 2026
Merged

bketelsen merged 10 commits into
mainfrom
feat/packaged-update-units

Conversation

@frostyard-machines

@frostyard-machines frostyard-machines commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Now stacked on #458 (after review). #458 is merged into this branch with commit 00a5ae1, so EnableDaemon and DisableDaemon take the operation lock on every path, including the packaged-units path. Merge #458 first. Review 9cf4ddd and the resolution in 00a5ae1.

Phase 2 of plan 0001, which implements ADR-0016, section "Units" and the daemon status part of "Status and logs".

Review follow-ups (Murbella) in 00a5ae1: the lock in daemon enable and daemon disable (test TestPackagedDaemonTakesTheLock); TimeoutStartSec=2h on the service (pinned by the contract tests); the docs say that an offline run fails the unit.

  • One source for the unit text. updex.DaemonUnits() returns the timer and service configuration. updex daemon enable and the release generator both use it.
    • Service: the ADR-0007 sandboxed oneshot, ExecStart=/usr/bin/updex features update --no-refresh, Wants= and After=network-online.target, and ConditionACPower=true.
    • Timer: OnCalendar=*-*-* 00/6:00:00, RandomizedDelaySec=3600s, Persistent=true, WantedBy=timers.target.
    • systemd.ServiceConfig gains Wants, After, Conditions and Comment. Output is unchanged for callers that do not set them.
  • Packaged units. The hidden updex units --output-dir DIR command and scripts/units.sh write both files. The script is a GoReleaser before-hook. nfpms.contents installs the files under /usr/lib/systemd/system/ with mode 0644. The package does not enable them: there is no maintainer script.
  • daemon enable:
    • When the packaged timer exists, it runs systemctl enable and then start and writes nothing.
    • When it does not exist, it writes the units to /etc/systemd/system/ with an ownership marker (# Generated by updex daemon enable; …).
  • daemon disable:
    • It runs systemctl disable and stop on the timer.
    • It removes only /etc units that carry the marker, or whose content exactly matches one of the 3 legacy ADR-0007 unit texts that earlier updex releases wrote.
    • It keeps any other file, reports it in KeptFiles, and refuses a symlink or a directory.
    • It never removes packaged units. The CLI prints the hint systemctl mask updex-update.timer.
  • daemon status:
    • It reports the source of the units (packaged or /etc), the unit files, the schedule (read from the file in use), and the next run (NextElapseUSecRealtime).
    • It also reports the last run: ExecMainExitTimestamp, and Result only after the service ran.
  • CI:
    • The new Systemd units job builds updex, generates the units with the release script, installs the binary to /usr/bin/updex, and runs systemd-analyze verify. The job fails on a non-zero exit or on any output line that names updex-update.
    • snapshot.yml checks the nightly amd64 .deb with scripts/check-deb-units.sh (dpkg-deb -c).

Checks

  • make fmt
  • make ci: ==> CI gate passed locally. Coverage is 87.4%, and .coverage-baseline is bumped from 86.9.
  • CLI/e2e green
  • Focused tests:
    • updex/units_hook_contract_test.go: runs scripts/units.sh and compares the output byte for byte with the generator. It pins --no-refresh, the schedule, ConditionACPower, the network-online lines and every SandboxDirectives line. It also pins the GoReleaser hook, both nfpms destinations, no maintainer scripts, the CI job steps, and the deb-check script (7 cases with a fake dpkg-deb).
    • updex/daemon_units_test.go: enable with packaged units writes nothing; enable without them writes the marker; 24 disable ownership cases (marked, foreign, legacy, edited legacy, packaged), real and dry run; refusal of a symlink and a directory; a status table (ran, failed, never ran, n/a).
    • cmd/updex: handler tests for the new behaviour, and the hidden units command.

Risk classification

  • Tier 4: Critical

Rationale:

  • This PR touches systemd/**, .goreleaser.yaml and .github/workflows/**.
  • Trust boundary:
    • The package now ships a root service and its timer. They are not enabled. Phase 7 enables them through a snosi preset.
    • daemon disable deletes root-owned files in /etc/systemd/system.
  • Abuse cases:
    • daemon disable never deletes a file without the updex marker or an exact legacy match.
    • Lstat refuses a symlink or a directory at a unit path.
    • Packaged units are never deleted.
    • The CI job uses sudo install only on the ephemeral runner.
  • Failure modes:
    • The snapshot .deb check runs after GoReleaser publishes dev. It turns the run red but cannot stop the publication.
    • A host with the old ADR-0007 units in /etc keeps them as overrides until daemon disable runs.
  • Rollback: revert this PR. A package built without the units removes them on upgrade. A host that enabled the timer keeps a dangling timers.target.wants link until systemctl disable.

Docs housekeeping

  • README.md, docs/design/overview.md, docs/design/packaging-and-maintainers.md, docs/specs/sdk-api.md and AGENTS.md (Release Automation) updated
  • Conformance aliases untouched

Verification

  • node scripts/check-docs.mjs green
  • systemd-analyze verify passes locally on both generated units, from a temp copy.
  • A local nfpm package built a .deb that lists both units as 0644 files, and scripts/check-deb-units.sh passes on it.

Not verified here:

  • GoReleaser Pro (Release config CI runs goreleaser check).
  • The snapshot step on GitHub.
  • The systemctl show value formats on a real host. Mock tests cover empty, n/a and 0.

…sfers together, add the operation lock

Phase 1 of plan 0001 (ADR-0016).
@github-actions github-actions Bot added documentation Improvements or additions to documentation go Pull requests that update go code github_actions Pull requests that update GitHub Actions code labels Oct 23, 2026
@codecov

codecov Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.96117% with 29 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
updex/daemon.go 91.21% 12 Missing and 9 partials ⚠️
cmd/updex/units.go 84.00% 2 Missing and 2 partials ⚠️
cmd/updex/daemon.go 96.87% 1 Missing and 1 partial ⚠️
systemd/mock_runner.go 60.00% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@frostyard-machines frostyard-machines left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Murbella (snosi owner): host and image review, comment only. Checked against ADR-0016, Brian's decisions (every image, 6 h, AC only) and my #457 review. I do not approve.

Verdict: no blocking finding. Units match ADR-0016: OnCalendar=*-*-* 00/6:00:00, RandomizedDelaySec=3600s, Persistent=true, WantedBy=timers.target, ConditionACPower=true, network-online Wants=/After=, --no-refresh, ADR-0007 sandbox. No maintainer script enables anything, so snosi's preset (Phase 7) is the only enablement. daemon disable never deletes packaged units and hints systemctl mask updex-update.timer, which is the durable opt-out on snosi. systemd-analyze verify in CI and the dpkg-deb -c check are the right gates for my Phase 7 build check.

Sandbox, from the host side: ProtectSystem=full keeps /run (lock), /var/lib/extensions* and /var/lib/updex (rollback records, #461) writable. /usr/.systemd-sysext stays readable. Good.

Non-blocking:

  1. Offline laptop gives a failed unit. Without network, network-online.target can still be reached, the downloads fail and the service exits non-zero. On a laptop that is often offline, systemctl is-system-running reports degraded several times a day. That matches the ADR ("exits non-zero when any enabled feature failed"), but consider treating "no route / DNS failure for every source" as a skip with a log line. At least say it in the docs.
  2. No TimeoutStartSec= backstop. Per-request timeouts (30 s manifest, 10 min download) and ADR-0008 retries bound one run, but nothing bounds the unit. A stuck run holds /run/updex/lock, and every manual updex features … gets ErrBusy until a reboot. A generous TimeoutStartSec= (for example 2 h) costs nothing.
  3. Background priority. A 1 GB incus image is downloaded, hashed and decompressed at normal priority on desktops. Consider Nice=10 and IOSchedulingClass=idle (both allowed under the current sandbox).
  4. 10 min download timeout on slow links. A compressed incus image on a slow link can exceed 10 min, fail, and start again from zero every 6 h (no resume, ADR-0008). This is older than this PR, but the timer makes it repeat silently. Track it as an issue.
  5. Merge order. After #458 merges, the rebase must add the operation lock to EnableDaemon and DisableDaemon, including enablePackagedDaemon.

Needs a real host or VM (plan "Done when"): the nightly dev .deb installs both units, disabled. On snosi I cannot dpkg -i into /usr; the image build after Phase 6 is the real check, plus systemctl is-enabled updex-update.timer = disabled on an image without the preset. The systemctl show value formats for daemon status also need a host. Host test plan: see my comment on #462.

…able/disable and add TimeoutStartSec=2h

Review follow-up (Murbella): EnableDaemon and DisableDaemon hold the
operation lock on the packaged-units paths too; the service gets a
TimeoutStartSec=2h backstop; the docs say an offline run fails the unit.
@bketelsen
bketelsen requested a review from bsherman October 23, 2026 16:30
@bsherman

Copy link
Copy Markdown
Contributor

Concern: daemon status can report a schedule that systemd does not use.

In updex/daemon.go, DaemonStatus calls readOnCalendar on the main timer file only. This ignores administrator drop-ins such as /etc/systemd/system/updex-update.timer.d/override.conf, the usual way to customize a packaged timer. It also ignores the reset semantics of an empty OnCalendar= assignment.

I reproduced the reset case against commit 00a5ae1dcf4ff11c5fb08afd3718065b4a78b7ac: a timer containing [Timer], OnCalendar=daily, OnCalendar=, then OnCalendar=weekly reports "daily, weekly" instead of "weekly". The focused regression test fails. With a drop-in override, status likewise continues to show the packaged six-hour schedule rather than the effective schedule.

Please obtain the effective timer configuration from systemd, or account for drop-in precedence and reset semantics. Add regression coverage for an overridden packaged timer and an empty assignment that clears earlier schedules.

Separately, this head includes #458 and therefore still inherits the rollback defect reported there.

…re failures

Review follow-up (bsherman, blocking): a regular file at the link path
is hard-linked to a backup before any link moves and renamed back when a
later transfer fails; other non-symlink entries are refused up front;
restore failures are joined into the returned error.
Review follow-up (bsherman): read OnCalendar from systemd (TimersCalendar),
else from the timer file and its drop-ins with reset semantics.
… into feat/packaged-update-units

# Conflicts:
#	.coverage-baseline
@frostyard-machines

Copy link
Copy Markdown
Contributor Author

Fixed in 494ca07 (Lucilla). #458's fix is merged in 387f94e.

  • DaemonStatus reads the effective schedule from systemd first: systemctl show updex-update.timer -p TimersCalendar --value. It parses each OnCalendar= value in the format that systemctl-show.c prints, in order.
  • When show is not supported, fails, or returns no entry, it reads files with systemd's rules: the timer file in use, then the updex-update.timer.d/*.conf drop-ins in /etc/systemd/system, /run/systemd/system and /usr/lib/systemd/system. A drop-in name in a higher directory hides the same name below, and the drop-ins apply sorted by name. Only lines in [Timer] count, and an empty OnCalendar= clears the earlier values.
  • Tests: your reset case (daily, empty, weekly gives weekly); a packaged timer with an /etc override.conf (gives the override); name hiding across directories; OnCalendar outside [Timer] is ignored; systemd output with 1 and 2 entries; a CLI text test.

bsherman
bsherman previously approved these changes Oct 23, 2026

@bsherman bsherman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Review follow-up (bsherman): when the transfer whose link failed cannot
be restored, its result and the returned error carry the restore failure
and say that the link may point at the new version.
…units

# Conflicts:
#	.coverage-baseline
#	updex/daemon.go
@bketelsen
bketelsen added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit b0a43e2 Oct 24, 2026
19 checks passed
@bketelsen
bketelsen deleted the feat/packaged-update-units branch October 24, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation github_actions Pull requests that update GitHub Actions code go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants