directory-cleaner
A daemon that puts a TTL on directories, built the way the rfs vc daemon is. It cleans every
directory it holds a job for, each on its own period, and serves a control panel at
http://127.0.0.1:7789.
The panel
- Type a directory into the bar and press Enter to add it. A new job starts stopped, keeping files
for
P30Dafter they were last read and sweeping everyPT1H, so nothing is deleted until it is started. - Each row has explorer, sweep now (runs once, started or not), start/stop and remove (click twice).
- Selecting a row shows its settings, its runs and its log; with nothing selected the log is the daemon's own.
| setting | meaning |
|---|---|
| delete after | delete a file this old, in the archive or in place |
| archive after | move a file this old into <directory>\archive first; empty deletes in place |
| every | how long to wait between sweeps |
| includes, excludes | patterns relative to the directory, comma separated, read the way rfs reads -i and -e |
| age files by when they were written | by default a file ages from when it was last read |
Durations are ISO 8601: PT20S, PT12H, P30D. A month or a year in one counts as a twelfth of
365 days or 365 days, so the form writes everything back in days, hours, minutes and seconds (P1M
reads back as P30DT10H). An empty directory goes once it has not changed for delete after. Links
are never followed or removed.
State and logs
- The jobs and their runs are kept in the ClickHouse database
directory_cleaner, declared inrdb_directory_cleaner/clickhouse. - Everything the daemon logs ships to the sniffer stream
logs.directory_cleaner, declared in the copy of the logs project underrdb_logs/clickhouse, and the panel reads it back.
The variables are in .env.example.
Layout
main.go Execute, close the logger, set the exit status
cmd/root.go the bare command is the daemon
cmd/version.go prints what `task build` stamped in
internal/config.go every DIRECTORY_CLEANER_ variable, in one struct
internal/daemon/ the daemon: jobs, sweep, runs, store, log reader, HTTP API
internal/daemon/ui/ the panel, an Astro and Svelte build embedded into the binary
Building
task lint runs nag, task test the Go tests, task build builds the panel with bun, then the
binaries, and installs the windows one. The panel's build is generated rather than committed, so a
clean clone runs task (or bun install and go generate ./...) before go build works.