cleanup: scheduled auto-cleanup via systemd timer#29
Merged
Conversation
Session files accumulate without bound; ssync cleanup exists but is manual. Add scheduling via systemd timers, not a daemon-internal scheduler (issue #24). New subcommand: ssync cleanup-timer enable|disable|status installs a ssync-cleanup.service/.timer pair running ssync cleanup --apply, user units as a regular user, system units as root with --user/--config under the same mode rules as service install. The oneshot reuses the daemon hardening set, sandboxed to the session dirs. --every accepts 2d/7d-style periods, weekly, or a raw calendar expression (validated with systemd-analyze at enable time). Expressible durations become calendar shorthands and gain Persistent=true catch-up; other day counts run on unit uptime via OnUnitActiveSec. --keep defaults to 90d unless --unnamed is the only selector. NixOS and home-manager modules gain services.ssync.autoCleanup { enable, schedule, keep, unnamed }; the shared hardening set is factored into one attrset used by both the daemon and the cleanup oneshot. The vm-module test covers the rendered ExecStart, the enabled timer, and a live oneshot run. Deletions propagate mesh-wide through the tombstone path: a timer on one machine prunes all machines. Documented loudly in setup.md next to the options. Closes #24.
Review of the cleanup-timer PR found one real hazard and a set of polish items: - hm-module: pull RuntimeDirectory and ReadWritePaths out of the shared hardening set into per-unit Service blocks. systemd does not ref-count runtime dirs shared between units (systemd#5394): every cleanup oneshot exit removed /run/user/$UID/ssync under the running daemon, silently demoting SecretFile from the runtime tmpfs to PrivateTmp. The oneshot also loses its needless dataDir write grant. - cleanup-timer enable: re-check access on pre-existing session dirs after create_write_paths, same as service install — a root-owned leaf otherwise fails only when the timer first fires. - schedule_of: checked_mul on the --every day/week count; an overflowing count is now a loud error instead of a wrap. - --keep help: match the code — the 90d default is skipped whenever --unnamed is given, not only when it is the only selector. - extract ensure_install_mode and remove_units into service.rs, shared by service install/uninstall and cleanup-timer enable/disable. - bundle keep/unnamed/agent into CleanupSelectors; drops the too_many_arguments allow.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Session files accumulate without bound;
ssync cleanupexists but is manual. This adds scheduled auto-cleanup per issue #24 — scheduling belongs to systemd timers, not a daemon-internal scheduler.CLI (plain-binary deployments)
ssync cleanup-timer enable|disable|statusinstalls assync-cleanup.service/.timerpair runningssync cleanup … --apply:--user/--config, same mode rules and access checks asssync service install--everyaccepts2d/7dperiods,weekly, or a raw calendar expression (validated withsystemd-analyze calendarat enable time — one loud error instead of a timer that never fires). Expressible durations normalize to calendar shorthands and gainPersistent=truecatch-up; other day counts run on unit uptime (OnUnitActiveSec)--keepdefaults to90dunless--unnamedis the only selector; keep/agent are validated at enable timeNixOS / home-manager modules
services.ssync.autoCleanup = { enable, schedule, keep, unnamed }generates the same oneshot + timer (Persistent=true,RandomizedDelaySec=1h,After=ssync.service). The shared hardening set is factored into one attrset used by both the daemon and the cleanup service. An assertion rejects a configuration that selects nothing.Semantics (documented in setup.md)
Testing
--keepdefaulting, unit rendering (oneshot/ExecStart/User/ReadWritePaths, persistent vs monotonic timer), unit-hostile value rejectionExecStart … cleanup --keep 90d --unnamed --apply, and a live oneshot run under hardening — passing locally-D warnings, full workspace tests,nix fmt -- --ciall cleanVersion bumped 0.11.1 → 0.12.0 (feature).
Closes #24.