Skip to content

feat: run scheduled tasks with Supercronic and support a custom crontab - #109

Open
dgibbs64 wants to merge 5 commits into
mainfrom
feat/supercronic
Open

dgibbs64 wants to merge 5 commits into
mainfrom
feat/supercronic

Conversation

@dgibbs64

@dgibbs64 dgibbs64 commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Replaces the system cron service with Supercronic, running as the linuxgsm user, and adds support for a persistent custom crontab.

Builds on the ideas in #94 (@WildPenquin) and #95 (@snowyyd), who are credited as co-authors. Supersedes both; the 26.04, single-Dockerfile and Node.js parts of #95 already landed in #108.

Problems this fixes

  1. Scheduled jobs ran without the container environment. Cron wipes the environment, so jobs didn't see LGSM_* settings. For example, backups used /app/serverfiles instead of /data/serverfiles (question for linuxgsm/root user, and custom crontab docker-gameserver#39).
  2. Update checks silently broke in hardened setups. Under --security-opt no-new-privileges, crontab can't write the schedule, but the entrypoint still reported that update checks were scheduled (test T8 below).
  3. Custom schedules were lost on every restart, because the entrypoint overwrote the crontab ([Feature]: LGSM would utilize user-provided file for CRONTAB jobs LinuxGSM#4584, docker-gameserver#39, docker-gameserver#101, Container user linuxgsm crontab can be saved optionally #94).
  4. UPDATE_CHECK values over 59 silently ran hourly, e.g. */90 (cron's minute field stops at 59).

Changes

  • Dockerfile: remove the cron package. Install Supercronic v0.2.49, pinned, with its published SHA1 checked at build time. Add ENV CRONTAB_FILE=/data/crontab.
  • entrypoint.sh: no longer starts the root cron service.
  • entrypoint-user.sh:
    • Supercronic always runs on an internal crontab, and a 30 second loop refreshes it. While /data/crontab exists it is used as-is (it lives on the data volume, so it survives restarts and image updates); otherwise one update job is generated from UPDATE_CHECK.
    • Creating, editing or deleting /data/crontab takes effect within 30 seconds, with no restart. Deleting it switches back to UPDATE_CHECK. Polling (rather than inotify on /data) also catches host-side edits on bind mounts where inotify events don't reach the container.
    • UPDATE_CHECK: 1-59 minutes, or whole hours up to 1440. Other values fall back to 60 with a warning; 0 disables.
    • Every change is checked with supercronic -test first. An invalid file is logged and the previous schedule stays active.
    • Scheduling starts after the server has started, so jobs can't collide with the initial install or update.
    • Job output that isn't redirected appears in docker logs (-passthrough-logs).
  • CI: the smoke test checks that supercronic is present and can parse a crontab.
  • README: new "Scheduled tasks" section covering the timezone (TZ), UPDATE_CHECK values, common task types (update, restart, backup, update-lgsm, mods/workshop updates, send, wipe), editing the file, and scheduling from the host.

Testing

Built from this branch on a test server (Ubuntu 26.04 image) and tested with jc2server:

Test Result
T1 Default UPDATE_CHECK=60 Schedule 0 */1 * * *; supercronic runs as linuxgsm; no root cron service
T2 UPDATE_CHECK=1 Scheduled update ran; LinuxGSM logged core_exit.sh exiting with code: 0
T3 UPDATE_CHECK=90 Warning, falls back to hourly
T4 UPDATE_CHECK=0 Nothing scheduled
T5 Custom /data/crontab Job ran as linuxgsm and saw LGSM_SERVERFILES=/data/serverfiles, LGSM_CONFIG, GAMESERVER, HOME=/data. Output appeared in docker logs. A line added while running took effect without a restart.
T6 Invalid crontab Clear error naming the bad line; container stays running and healthy
T7 --security-opt no-new-privileges Custom job ran every minute as linuxgsm
T8 Current image (cron), no-new-privileges ❌ /var/spool/cron/: mkstemp: Permission denied, yet logs "update will check every 1 minutes"

Live-reload tests (after the 30 second refresh loop was added), one container kept running throughout:

Test Result
L1 Start with no /data/crontab Default hourly update check, Supercronic running
L2 Create /data/crontab while running Picked up within 30 s, job ran
L3 Edit it Reloaded, new line's output appeared in docker logs
L4 Make it invalid Error names the bad line; previous schedule kept running (job count 4 -> 6)
L5 Delete it Back to the hourly UPDATE_CHECK schedule; custom job stopped
L6 UPDATE_CHECK=0, no file "update checks are disabled", Supercronic idle, no errors
L7 no-new-privileges, file created while running Job ran as linuxgsm

Also checked with shellcheck, hadolint (no new findings), actionlint and Prettier.

Notes

  • Behaviour change: running crontab -e inside the container no longer works. It never persisted anyway, because the entrypoint overwrote the crontab. Use /data/crontab instead.
  • Dependabot can't bump the Supercronic version. Update SUPERCRONIC_VERSION and SUPERCRONIC_SHA1SUM together from the release notes.

Closes #94
Closes #95

dgibbs64 and others added 5 commits October 13, 2026 22:11
Replace the system cron service with Supercronic, run as the linuxgsm user.

- Scheduled jobs now get the container environment. Cron wiped it, so jobs
  ran without LGSM_* settings (e.g. backups used /app/serverfiles instead
  of /data/serverfiles, docker-gameserver#39).
- No root service or setgid crontab binary is needed, so the container
  works with --security-opt no-new-privileges.
- A crontab at /data/crontab (CRONTAB_FILE) is used instead of
  UPDATE_CHECK, survives restarts and image updates, and is reloaded on
  change. Invalid crontabs are logged and do not stop the container.
- UPDATE_CHECK is converted to a valid schedule (1-59 minutes, or whole
  hours up to 24); other values fall back to 60 minutes with a warning
  instead of silently running hourly.
- Supercronic is pinned and its SHA1 checksum verified at build time.
- Scheduling starts after the server has started, so jobs cannot collide
  with the initial install or update.

Based on ideas from #94 and #95.

Co-authored-by: Agustín <17956512+snowyyd@users.noreply.github.com>
Co-authored-by: WildPenguin <3398736+WildPenquin@users.noreply.github.com>
Supercronic now always runs on an internal crontab, and a 30 second loop
refreshes it from /data/crontab, so creating, editing or deleting the file
takes effect without restarting the container (deleting it switches back
to UPDATE_CHECK). Polling also catches host-side edits on bind mounts
where inotify events don't reach the container. Each change is validated
first; an invalid file is logged and the previous schedule stays active.

README: document the timezone, UPDATE_CHECK values, common task types,
editing the file and scheduling from the host.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant