diff --git a/Dockerfile b/Dockerfile index 876f3ff..56e8470 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,11 @@ FROM python:3.13-alpine # mariadb-client -> mariadb-dump # restic -> the backup engine # 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 \ mariadb-client \ restic \ docker-cli \ - supercronic \ tzdata \ && adduser -u 99 -D -G users -h /config -s /sbin/nologin backup diff --git a/README.md b/README.md index 0593288..aee92dc 100644 --- a/README.md +++ b/README.md @@ -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 | | `SEAFILE_CONTAINER` | `seafile` | container to stop in cold mode | | `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 `s3:` backend. @@ -76,6 +76,24 @@ mariadb -h -u root -p < /restore/config/db//seafile-databases.sql The dump is written with `--add-drop-table`, so it can also be replayed over an 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 ```sh diff --git a/entrypoint.sh b/entrypoint.sh index 9918d14..b1af1ab 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -3,10 +3,25 @@ set -eu : "${CRON:=0 3 * * *}" -# /opt is read-only when the container runs with read_only: true, so the -# generated crontab lives on the tmpfs. -CRON_CONFIG_FILE=/tmp/crontab +# busybox crond only loads crontab files owned by uid 0, and before every job +# it drops to the crontab's user with initgroups()/setgid()/setuid(). So this +# 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"