feat: schedule with busybox crond instead of supercronic

Same scheduler qbit-maid uses: entrypoint.sh writes the crontab and execs
crond -f. Drops the supercronic package from the image.

- crontab lives in /tmp/crontabs because the rootfs is read-only
- MAILTO= keeps job output on crond's stdout/stderr (container log), which
  is what supercronic -passthrough-logs provided
- busybox crond only loads crontab files owned by uid 0 and calls
  initgroups() per job, so the container needs root + CAP_SETGID; the
  entrypoint now fails fast (exit 78) when it is not root
- no @reboot job: a container restart must not start a backup
This commit is contained in:
trex Bot committed 2026-11-24 22:24:29 -06:00
1 parent 313db934e4
commit ce825c7526
3 files changed
+40 -8

No files matched your search

+1 -2
View File
@@ -3,12 +3,11 @@ FROM python:3.13-alpine
# mariadb-client -> mariadb-dump # mariadb-client -> mariadb-dump
# restic -> the backup engine # restic -> the backup engine
# docker-cli -> only used when COLD_BACKUP=true (docker exec into seafile) # docker-cli -> only used when COLD_BACKUP=true (docker exec into seafile)
# supercronic -> cron with passthrough logs # busybox crond -> the scheduler (ships with the base image, no extra package)
RUN apk add --no-cache \ RUN apk add --no-cache \
mariadb-client \ mariadb-client \
restic \ restic \
docker-cli \ docker-cli \
supercronic \
tzdata \ tzdata \
&& adduser -u 99 -D -G users -h /config -s /sbin/nologin backup && adduser -u 99 -D -G users -h /config -s /sbin/nologin backup
+19 -1
View File
@@ -60,7 +60,7 @@ record nothing, which is why the query string is the only form used here.
| `COLD_BACKUP` | `false` | stop Seafile around the run | | `COLD_BACKUP` | `false` | stop Seafile around the run |
| `SEAFILE_CONTAINER` | `seafile` | container to stop in cold mode | | `SEAFILE_CONTAINER` | `seafile` | container to stop in cold mode |
| `FAIL_ON_PARTIAL` | `false` | treat restic exit 3 as a failure | | `FAIL_ON_PARTIAL` | `false` | treat restic exit 3 as a failure |
| `CRON` | `0 3 * * *` | supercronic schedule | | `CRON` | `0 3 * * *` | crond schedule (standard 5-field) |
`AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` are read by restic itself for the `AWS_ACCESS_KEY_ID` / `AWS_SECRET_ACCESS_KEY` are read by restic itself for the
`s3:` backend. `s3:` backend.
@@ -76,6 +76,24 @@ mariadb -h <host> -u root -p < /restore/config/db/<stamp>/seafile-databases.sql
The dump is written with `--add-drop-table`, so it can also be replayed over an The dump is written with `--add-drop-table`, so it can also be replayed over an
existing database. existing database.
## Scheduling
The container runs busybox `crond` in the foreground (the same scheduler
qbit-maid uses). `entrypoint.sh` writes `/tmp/crontabs/root` from `CRON` and
execs `crond -f -c /tmp/crontabs`; the rootfs is read-only, so the crontab
lives on the tmpfs. `MAILTO=` is set empty so job output stays on crond's own
stdout/stderr, i.e. the container log.
Two consequences of busybox crond:
* it only loads crontab files owned by **uid 0**, so the container must run as
root (`user: '0:0'` — which the Seafile block permissions require anyway);
* before each job it calls `initgroups()`, so the container needs
`CAP_SETGID` on top of `CAP_DAC_OVERRIDE`. Without it the job is forked and
then dies with `crond: can't set groups: Operation not permitted`.
There is no `@reboot` job: a container restart does not start a backup.
## Build ## Build
```sh ```sh
+20 -5
View File
@@ -3,10 +3,25 @@ set -eu
: "${CRON:=0 3 * * *}" : "${CRON:=0 3 * * *}"
# /opt is read-only when the container runs with read_only: true, so the # busybox crond only loads crontab files owned by uid 0, and before every job
# generated crontab lives on the tmpfs. # it drops to the crontab's user with initgroups()/setgid()/setuid(). So this
CRON_CONFIG_FILE=/tmp/crontab # container has to run as root — the compose file sets user: '0:0' anyway,
# because Seafile writes some block files 0600 root:root.
if [ "$(id -u)" != "0" ]; then
echo "entrypoint: crond needs root (crontab files must be owned by uid 0)" >&2
exit 78
fi
printf '%s /usr/local/bin/seafile-backup\n' "$CRON" > "$CRON_CONFIG_FILE" # The rootfs is read-only, so the generated crontab lives on the tmpfs.
CRON_DIR=/tmp/crontabs
mkdir -p "$CRON_DIR"
exec supercronic -passthrough-logs -quiet "$CRON_CONFIG_FILE" # MAILTO= (empty) keeps job output on crond's own stdout/stderr, i.e. the
# container log — the passthrough supercronic used to provide.
{
echo 'MAILTO='
printf '%s /usr/local/bin/seafile-backup\n' "$CRON"
} > "$CRON_DIR/root"
chmod 0600 "$CRON_DIR/root"
exec crond -f -c "$CRON_DIR"