From 93b5370dbf9fce8733a02818d9f04c7e7d7d366f Mon Sep 17 00:00:00 2001 From: Daniel Samson Date: Sat, 17 Oct 2026 13:53:56 +0100 Subject: [PATCH] docs: update README for the working binary Co-Authored-By: Claude Sonnet 5.5 --- README.md | 108 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 89 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index dfd50ff..ec70f11 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,10 @@ # Zag Job Daemon (Cross-Platform) -> **Status:** early development. Zag is the [Zig](https://ziglang.org) port of -> [barn](https://gitea.samson.media/samson-media/barn), the Java job daemon. The goal is -> CLI and on-disk compatibility with barn so the two can be swapped without -> changing clients. +> Zag is the [Zig](https://ziglang.org) port of +> [barn](https://gitea.samson.media/samson-media/barn), the Java job daemon. It keeps barn's +> CLI, JSON/XML output and job directory layout so clients can switch by changing the binary +> name, and fixes the places where barn's behaviour did not match its documentation (see +> [Migration from barn](#migration-from-barn)). A **cross-platform service** for managing long-running jobs that involve downloading and uploading media via WebDAV, using FFmpeg to analyse and transcode video, with strong guarantees around durability, @@ -52,14 +53,54 @@ a low idle memory footprint, and easy cross-compilation to every supported platf --- +## Installation + +### Linux / macOS + +The installer downloads the latest release, installs the binary and registers a service +(systemd on Linux, launchd on macOS). The repository is private, so provide an access token: + +```bash +export ZAG_TOKEN= +curl -fsSL -H "Authorization: token $ZAG_TOKEN" \ + https://gitea.samson.media/samson-media/zag/raw/branch/main/install.sh | sh +``` + +`ZAG_VERSION`, `ZAG_PREFIX` and `ZAG_NO_SERVICE=1` tune the install; see the header of `install.sh`. + +### Manual + +Download `zag-linux-x64`, `zag-linux-arm64`, `zag-macos-arm64` or `zag-macos-x64` from the +[releases page](https://gitea.samson.media/samson-media/zag/releases), check it against +`SHA256SUMS`, and put it on your `PATH`: + +```bash +chmod +x zag-linux-x64 && sudo mv zag-linux-x64 /usr/local/bin/zag +zag --version +``` + +The binaries are static and need no runtime. Windows is not supported yet. + +### Setting up the service + +```bash +sudo zag service install # system-wide (as root); without sudo it installs for your user +zag service start +zag service status +``` + +Once installed, `zag service start|stop|restart` go through systemd/launchd. Without +installing, `zag service start` runs a detached daemon of its own. + ## Building -Requires Zig 0.16.0 or newer. +Requires Zig 0.16.0 or newer. Linux builds default to musl (a static binary). ```bash zig build # build to zig-out/bin/zag -zig build test # run tests -zig build -Doptimize=ReleaseSafe # release build +zig build test # unit tests +zig build e2e # end-to-end smoke test against the built binary +zig build -Doptimize=ReleaseSafe -Dstrip=true # release build (~1 MB) ``` Cross-compile with `-Dtarget`, for example: @@ -72,19 +113,31 @@ zig build -Doptimize=ReleaseSafe -Dtarget=aarch64-linux --- +## Global options + +| Option | Description | +|--------|-------------| +| `-o, --output {human\|json\|xml}` | Output format (default `human`) | +| `--config ` | Configuration file to merge on top of the system and user files | +| `--offline` | Run without the service: same code, in this process (`zag run --offline` executes the job and prints its final state) | +| `--barn-dir ` | Data directory, overriding `storage.base_dir` (also relocates the socket) | + ## Zag command This project creates a simple CLI commandlet with sub-commands. -- `zag service {start|stop|restart|reload|status|logs}` - manages the zag service +- `zag service {start|stop|restart|reload|status|logs|install|uninstall}` - manages the zag service - `zag run {command}` - starts job - `zag status` - gets the status of all jobs running - `zag describe {jobId}` - collects all the info from /tmp and display it -- `zag usage {jobId}` - shows resource usage (CPU, memory, disk) for a job +- `zag usage {jobId}` - shows resource usage (CPU, memory, disk, GPU) for a job - `zag kill {jobId}` - kills a job - `zag clean` - performs clean up - `zag config install` - installs default configuration files - `zag config show` - shows effective configuration +- `zag config validate --file ` - checks a configuration file +- `zag config init` - writes a default user configuration file +- `zag autocompletion {--bash|--zsh}` - prints a shell completion script zag is just one binary for both the service and the client. The client uses IPC to communicate with the service. @@ -191,19 +244,36 @@ zag run --load-level=high -- curl -O https://example.com/file.zip | Area | Barn | Zag | |------|------|-----| -| Language | Java 21 | Zig | +| Language | Java 21 (GraalVM native image) | Zig, static binary of about 1 MB | | Binary | `barn` | `zag` | | Data dir | `/tmp/barn` | `/tmp/zag` | -| Config dir | `/etc/barn/` | `/etc/zag/` | +| Config | `/etc/barn/barn.conf`, `~/.config/barn/barn.conf` | `/etc/zag/zag.conf`, `~/.config/zag/zag.conf` | +| Environment overrides | `BARN_
_` | `ZAG_
_` (`ZAG_LOAD_LEVELS_MAX_HIGH_JOBS` works) | +| Socket | `/barn.sock` | `/zag.sock` (mode 0600) | -The CLI surface, `--output={json|xml}` formats, job states, load levels and retry -semantics are intended to match barn exactly. Anything that differs will be documented here. +The CLI surface, `--output={json|xml}` formats, job states, load levels and the on-disk job +layout match barn. Where barn's code disagreed with its own documentation, zag follows the +documentation: + +- `zag clean` behaves the same offline and through the service: with none of `--all`, + `--older-than` or `--job-id` it removes nothing. +- `kill` ends the job as `canceled` without racing the runner, and also cancels *queued* jobs. +- A failed job is **actually retried** (`--max-retries`, `--retry-delay`, `retry_on_exit_codes`, + exponential backoff with jitter); barn only retried jobs orphaned by a crash. +- `--timeout` and `default_timeout_seconds` are enforced (symbolic exit code `timeout`). +- `service reload` re-reads the configuration (also on SIGHUP) instead of doing nothing. +- `heartbeat_interval_seconds` is honoured, and `storage.base_dir` / `service.ipc_socket` are + used consistently by the daemon *and* the CLI. +- Jobs run in their own process group, so `kill` and `service stop --force` take down the whole + process tree. Job directories are created and deleted atomically. +- Without `config install`, the built-in `.load` lists still classify `ffmpeg` as HIGH and + `curl` as LOW. +- `config show` calls the load-limit section `load_levels`, matching the config file. + +Not implemented yet: Windows, `max_disk_usage_gb`, `preserve_work_dir`, auto-update. ## Project Layout -``` -build.zig build script -build.zig.zon package manifest -src/main.zig CLI entry point -src/root.zig library root -``` +See [AGENTS.md](AGENTS.md) for the module map. In short: `src/cli*.zig` is the command line, +`src/service.zig` the daemon core, `src/scheduler.zig` / `src/runner.zig` run jobs, +`src/repository.zig` persists them, `src/ipc.zig` is the socket protocol.