Repository navigation
snapraid-daemon mode (experimental) - #25
Merged
Merged
Conversation
A daemon engine on snapraid-daemon's REST API (tested with 2.0rc2 and SnapRAID 15.0rc2) implements the SnapRAID engine interface: jobs are queued with /v1/schedule and followed through /v1/tasks and /v1/activity for their messages and progress, abort goes to /v1/stop, status, diff, SMART and the power state come from /v1/array and /v2/disks. touch and status, which the daemon has no task for, go to the CLI engine. When the daemon runs on the same machine, the report of a run is read from its SnapRAID log, otherwise from the task. A daemon serves one array; several run as snapraidd@<name>. On the Automation page each configuration can get its daemon (address, optional login, a connection test that warns about the daemon's own schedule, spindown, Docker pause or notifications); configurations without one keep running on the CLI, and one job still runs at a time across all of them. The settings live in engine.json and switch the engine without a restart; scheduler and spindown follow through activeEngine. The interface gains readLastRuns, as the daemon's runs are not in the UI's logs. The daemon does not count files per disk, so the disks table shows a dash there, and runs without a readable log get no log link. The engine contract now also runs against a live daemon when SNAPRAID_TEST_DAEMON_URL is set and passes for the fake, the CLI and the daemon engine. In CI, without a daemon, a stand-in that answers like snapraid-daemon 2.0rc2 covers following tasks, progress, abort, the fallback, auth, errors and the JSON mapping; the settings and which engine runs which config have their own tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JuXnquCPdbG5sBbDyin7yF
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.
Lets running snapraid-daemon instances run the jobs of their arrays instead of SnapRAID UI calling SnapRAID itself. It is built on the engine interface from #23, off by default and marked experimental. Configurations without a daemon keep running on the CLI.
Daemon engine (
backend/src/engine/daemon-engine.ts)sync,scrub,check,fix,diff,smartandprobeare queued withPOST /v1/schedule./v1/tasksand/v1/activityare polled for the task's messages (live output) and progress. Abort goes toPOST /v1/stop.touchandstatusgo to the CLI engine, because the daemon has no task for them./v1/arrayand/v2/disks; a disk the daemon ratesdegradedbecomes a "missing" disk issue, which pauses schedules as before.difftask, then/v1/array?limit_diffs=…./v2/disks. SMART attribute names are mapped back to ids for the UI's assessment.readLastRuns. The dashboard's last sync and scrub come from the daemon's task history, since its runs are not in the UI's logs.Several arrays
A daemon serves one array; for several, snapraid-daemon 2.0 runs one instance each (
snapraidd@<name>, own config and port).engine.jsonholds a list of daemons, one per configuration.buildEngine()runs each listed configuration on its daemon and the others on the CLI. One job still runs at a time across all of them.Switching takes effect without a restart.
PUT /api/engineswaps the engine; it refuses while a job runs. Scheduler and spindown follow throughactiveEngine.UI
A snapraid-daemon card on the Automation page. Each entry has the configuration it serves, the address and an optional login; the password is masked and stored in
engine.jsonwith mode 600. Test connection shows the daemon and SnapRAID version and the array it serves. It warns when the daemon has its own schedule, spindown, Docker pause or notifications set, or serves another array than the one picked.Known gaps (documented)
Tests
engine-contract.tsnow also runs against a live daemon whenSNAPRAID_TEST_DAEMON_URLandSNAPRAID_TEST_DAEMON_CONFare set. It passes for the fake engine, the CLI engine (SnapRAID 14.10) and the daemon engine (snapraid-daemon 2.0rc2 with SnapRAID 15.0rc2, built here). Theoutputstep now runsdiffinstead ofstatus, which every engine runs itself.daemon-engine.test.ts(14 tests) uses a stand-in that answers like 2.0rc2. It covers a sync with output and progress, scrub arguments, failed runs with and without a readable log, abort, the fallback, asmartjob, busy reads, the diff, basic auth, unreachable and 401, the JSON mapping, last runs, and a task the daemon never runs.engine-settings.test.tscovers masked passwords, validation (one daemon per configuration), which engine runs which configuration, and the connection check with its warnings.deno test120 passed and 2 ignored (no CLI binary or daemon), 122 passed with both.biome check,npm run typecheck,npm test(24) andnpm run buildpass, andmkdocs build --stricthas no warnings.Docs
docs/automation.mdhas a new section: setup, one instance per array, which daemon options to turn off, what runs where, and the limitations.architecture.mdmaps each engine method for both engines and lists the known gaps.development.mdexplains how to run the contract against a daemon.configuration.mdandsecurity.mdlistengine.json.🤖 Generated with Claude Code
https://claude.ai/code/session_01JuXnquCPdbG5sBbDyin7yF
Generated by Claude Code