No description
  • Go 87.9%
  • JavaScript 5.2%
  • Just 3%
  • CSS 2.3%
  • Dockerfile 1%
  • Other 0.6%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Sophie be3e34c3ac
All checks were successful
Build Docker Image / build (push) Successful in 4m57s
Merge pull request 'Run jobs side by side, up to --max-parallel' (#10) from pixel/594-run-jobs-side-by-side-up-to-max-parallel into main
Reviewed-on: #10
Reviewed-by: pixel-board <pixel-board@m.ac.nz>
2026-12-04 00:59:47 +11:00
.forgejo/workflows chore(deps): update dependencies-major 2026-11-14 13:01:22 +00:00
config Run jobs side by side, up to --max-parallel 2026-12-03 22:18:07 +11:00
deploy Document the metrics and turn them on in the examples 2026-11-30 21:08:45 +11:00
example-jobs add a web interface + justfile 2026-09-06 16:26:06 +10:00
metrics Run jobs side by side, up to --max-parallel 2026-12-03 22:18:07 +11:00
rclone gofmt the files that were not formatted 2026-11-30 21:08:44 +11:00
runner Never run two bisync jobs at the same time 2026-12-03 22:45:41 +11:00
scheduler Never run two bisync jobs at the same time 2026-12-03 22:45:41 +11:00
ui Run jobs side by side, up to --max-parallel 2026-12-03 22:18:07 +11:00
web Never run two bisync jobs at the same time 2026-12-03 22:45:41 +11:00
.dockerignore build docker container(s) 2026-09-06 15:35:55 +10:00
.gitignore add a web interface + justfile 2026-09-06 16:26:06 +10:00
AGENTS.md Never run two bisync jobs at the same time 2026-12-03 22:45:41 +11:00
Dockerfile Document the metrics and turn them on in the examples 2026-11-30 21:08:45 +11:00
go.mod Export per-job Prometheus metrics on a listener of their own 2026-11-30 21:08:45 +11:00
go.sum Export per-job Prometheus metrics on a listener of their own 2026-11-30 21:08:45 +11:00
justfile Document --max-parallel and what running in parallel costs 2026-12-03 22:18:07 +11:00
main.go Never run two bisync jobs at the same time 2026-12-03 22:45:41 +11:00
README.md Never run two bisync jobs at the same time 2026-12-03 22:45:41 +11:00
renovate.json chore(deps): add renovate.json 2026-08-08 01:06:26 +00:00

rclone-manager

Scheduling and monitoring for rclone sync jobs. Define jobs as YAML files and rclone-manager will run them on a schedule, showing live status either as a terminal UI or as a web dashboard.

Requirements

  • Go 1.26+
  • rclone installed and available on $PATH

Usage

rclone-manager --jobs <path-to-jobs-dir> [--poll <interval>] [--ui tui|web] [--max-parallel <n>]
Flag Default Description
--jobs (required) Path to directory containing job YAML files
--poll 5m How often to check for due jobs
--rclone-config $RCLONE_CONFIG Path to rclone.conf. Empty leaves rclone to its own default discovery (~/.config/rclone/rclone.conf, RCLONE_CONFIG_<REMOTE>_* env vars, ...)
--ui tui (or $RCLONE_MANAGER_UI) Interface to run: tui (terminal) or web (HTTP)
--web-addr :8080 (or $RCLONE_MANAGER_WEB_ADDR) Listen address for the web interface
--metrics-addr (empty, off) (or $RCLONE_MANAGER_METRICS_ADDR) Listen address for Prometheus metrics on /metrics, in either UI mode. Must differ from --web-addr
--max-parallel 1 (or $RCLONE_MANAGER_MAX_PARALLEL) How many jobs may run at the same time; must be at least 1. See Running jobs in parallel

Running jobs in parallel

By default (--max-parallel 1) jobs run one at a time, as they always have: a long run of one job holds back every other job until it ends.

With --max-parallel N, up to N jobs run side by side. Due jobs and "run now" requests wait in one queue, and start from it in the order they were queued whenever fewer than N jobs are running (but see bisync, below). The same job never runs twice at once: while a job is queued or running, it is not queued again, and "run now" answers 409.

Two bisync jobs never run at the same time either: a queued bisync waits while another bisync runs, and other jobs behind it in the queue may start first. bisync jobs still run alongside copy and sync jobs. This is so that what rclone logs during a bisync run, which decides whether it is retried automatically (see below), cannot come from another bisync.

Running in parallel is not free:

  • Connections to a remote add up across jobs. Each job opens up to its checkers + transfers connections (rclone's defaults are 8 and 4), so two jobs against the same remote open twice as many. An sftp server, for example, may cap the sessions one account can hold; lower the jobs' checkers/transfers flags, or N, to stay under it.
  • Memory adds up too. Each running job needs its own memory, all in the one rclone daemon; a bisync --resync in particular holds a record of every file.
  • Errors are less detailed. When a job fails, rclone-manager adds the ERROR lines from rclone's recent log to the error it shows. Those lines do not say which job they came from, so for a job that ran alongside another job at any point, they are left out (it would otherwise risk showing another job's errors); the error then holds only what rclone's API reported for that job. The same goes for the log rclone hands back with a bisync run, which is everything rclone logged while it ran, not just the bisync's: only bisync's own "Must run --resync" and "Safety abort" lines are read from it. Those are its own, since no other bisync runs at the same time, so the automatic --resync/--force retry still works.

Interfaces

Both modes run the same scheduler and runner; they only differ in how you watch them.

--ui tui (default) renders a live dashboard in the terminal. Press q to quit.

--ui web serves the same information over HTTP and needs no TTY, which makes it the right choice under Kubernetes, Docker without -it, or anywhere you would rather point a browser than attach to a process.

rclone-manager --jobs ./my-jobs --ui web --web-addr :8080
Endpoint Description
GET / Dashboard: running jobs with live progress, the queue, upcoming schedule, run history
GET /api/state The same data as JSON — handy for scripting or testing; see below
POST /api/jobs/{name}/run Queue a job to run as soon as there is room for it, ignoring its schedule. 404 if unknown, 409 if already queued or running
GET /healthz, GET /readyz Liveness and readiness. Both are cheap and never touch rclone, so a long sync will not fail a probe

In /api/state, running lists every running job, longest-running first, each with its own rcloneJobId, startTime and progress; queue lists the jobs waiting to run, in the order they were queued (name and operation). Both are empty arrays, never null, when there is nothing to show. current is kept for clients written before jobs could run side by side: it is running[0], or null when idle.

The page polls /api/state once a second (backing off to every 15s while the tab is hidden). All assets are embedded in the binary — nothing is fetched from a CDN.

Metrics

Pass --metrics-addr (or set $RCLONE_MANAGER_METRICS_ADDR) to serve Prometheus metrics on GET /metrics:

rclone-manager --jobs ./my-jobs --ui web --metrics-addr :9090

Metrics work in both UI modes and are served on a listener of their own, never on the web interface's port; that listener serves nothing but /metrics. Besides the standard Go and process collectors (go_*, process_*), every job gets these series, labelled job_name:

Series Type Meaning
rclone_manager_job_runs_total{job_name,outcome} counter Finished runs; outcome is success or failure. A job that fails to start counts as a failure
rclone_manager_job_last_success_timestamp_seconds{job_name} gauge Unix time the last successful run ended. Absent until the job has succeeded in this process
rclone_manager_job_last_run_timestamp_seconds{job_name} gauge Unix time the last run ended, whatever its outcome
rclone_manager_job_duration_seconds{job_name} gauge How long the last finished run took
rclone_manager_job_transferred_bytes_total{job_name} counter Bytes transferred by finished runs
rclone_manager_job_transferred_files_total{job_name} counter Files transferred by finished runs

The label is job_name rather than job because Prometheus and vmagent set job on every scraped target themselves; with the default honor_labels: false a job label from rclone-manager would be renamed exported_job, and {job="<name>"} would match nothing.

Series are recorded when a run finishes. A bisync run that is retried automatically (after "Must run --resync", say) counts as one run: its outcome is the retry's, its duration runs from the first attempt's start, and its bytes and files cover both attempts. A run interrupted by shutdown is not counted: runs_total is not incremented, and the timestamps, duration and transfer counters are left as they were.

rclone's own rclone_* series (served by the rclone rcd that rclone-manager starts when the environment sets RCLONE_METRICS_ADDR) are no substitute: they are sums over every stats group, so they cannot tell jobs apart, and rclone-manager resets a job's stats group each time the job starts, so the rclone_*_total series go down and only ever describe the current runs.

Two caveats:

  • Everything starts empty after a restart. Nothing is persisted, so rclone_manager_job_last_success_timestamp_seconds is absent for a job until it first succeeds in the new process. An alert on "no success for too long" must handle the missing series (for example with absent(), or by falling back to the process start time), or a restart will silence it.
  • Counters are per process. They reset to zero on restart, as Prometheus counters do; use rate()/increase() rather than raw values.

Job format

Each .yaml / .yml file in the jobs directory defines one sync job:

name: my-backup
source: /path/to/source
destination: /path/to/destination
operation: sync          # sync, copy, or bisync
schedule: 1h             # Go duration (e.g. 30m, 6h) or cron expression (e.g. "0 2 * * *")
flags:                   # optional rclone flags
  checksum: true

Fields

Field Required Description
name yes Human-readable job name
source yes Source path or rclone remote
destination yes Destination path or rclone remote
operation yes sync, copy, or bisync
schedule yes Interval (Go duration) or 5-field cron expression
flags no Extra flags passed to rclone

Docker

The image never contains an rclone.conf — supply it at run time:

docker build -t rclone-manager .
docker run --rm -it \
  -v ~/.config/rclone/rclone.conf:/config/rclone.conf:ro \
  -v ./my-jobs:/jobs:ro \
  rclone-manager

Without a TTY, run the web interface instead:

docker run --rm -p 8080:8080 \
  -v ~/.config/rclone/rclone.conf:/config/rclone.conf:ro \
  -v ./my-jobs:/jobs:ro \
  rclone-manager --jobs /jobs --ui web

The image sets RCLONE_CONFIG=/config/rclone.conf, so mounting the file there is all that is needed. Point it elsewhere by overriding that env var or passing --rclone-config <path>; pass --rclone-config "" to define remotes purely through RCLONE_CONFIG_<REMOTE>_* env vars instead. If the configured path does not exist, startup fails with an explicit error rather than silently running with no remotes.

Read-only config mounts

Kubernetes secrets and :ro bind mounts are not writable, but rclone rewrites its config file whenever it refreshes an OAuth token. When the config is not writable, rclone-manager copies it to a private 0600 file under $TMPDIR at startup and points rclone at the copy. Refreshed tokens therefore last for the lifetime of the process and are re-derived from the refresh token after a restart. $TMPDIR must be writable — with a read-only root filesystem, mount an emptyDir at /tmp.

Kubernetes

deploy/kubernetes.yaml is a working example: the config arrives as a Secret mounted at /config/rclone.conf, and jobs as a ConfigMap at /jobs.

kubectl create secret generic rclone-config \
  --from-file=rclone.conf=$HOME/.config/rclone/rclone.conf
kubectl apply -f deploy/kubernetes.yaml

The example runs --ui web, so no TTY is needed: the container exposes port 8080, both probes point at it, and a Service fronts it. Open the dashboard with:

kubectl port-forward svc/rclone-manager 8080:80

then browse to http://localhost:8080. To run the TUI under Kubernetes instead, drop the --ui web args and set tty: true and stdin: true on the container, then attach with kubectl attach -it deploy/rclone-manager (detach with Ctrl-P Ctrl-Q).

Building

go build -o rclone-manager .

Local development

A justfile wraps the common tasks. Everything runs through Docker, so no local Go toolchain is needed — only just, docker, curl and jq.

just copy     # build the image, start the web interface, run the example copy job

example-jobs/ holds two jobs that copy between directories inside the container, so they exercise the scheduler, runner and rclone daemon end to end without needing a configured remote. just seeds the source tree under .local/data/ (git-ignored), which is also where you can inspect what was copied.

Recipe Description
just build Build the Docker image
just run Build and start the web interface on http://localhost:8080, with metrics on port 9090
just max_parallel=2 run The same with --max-parallel 2, so both example jobs can run at once when triggered together. max_parallel applies to just tui too
just copy run, then trigger the example copy job and print its result
just trigger <job> Trigger any job by name and wait for it to finish
just state Print /api/state as JSON
just metrics Print the rclone_manager_ lines from http://localhost:9090/metrics
just logs Follow the container logs
just tui Run the terminal UI against the same example jobs
just stop / just clean Stop the container / also delete the seeded data