Skip to content

[BUGFIX] Send the output of the cron jobs of docker-cronjob to the container log - #667

Draft
Kanti wants to merge 4 commits into
masterfrom
bugfix/cron-job-output
Draft

Kanti wants to merge 4 commits into
masterfrom
bugfix/cron-job-output

Conversation

@Kanti

@Kanti Kanti commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Split from #657: the output of cron jobs changes how cron behaves, so it gets a pull request of its own.

Why

Cron in Debian and Ubuntu mails the output of a job. Most containers run no mail server, so cron discards it and logs (CRON) info (No MTA installed, discarding output). Whatever a job that docker-cronjob adds prints, including its errors, is lost. BusyBox crond on Alpine already passes the output on to the container log.

What

  • docker-cronjob: begins /etc/cron.d/webdevops-docker with SHELL=/usr/local/bin/docker-cronjob-shell.
  • docker-cronjob-shell (new): cron runs each job of that file as docker-cronjob-shell -c <command>.
    • It runs the command with /bin/sh, as cron would, and sends stdout and stderr to syslog with logger -t cron-job[<pid>], one message per line and per 1 KiB of a longer line. syslog-ng writes them to the container log, or the file of LOG_STDOUT, as [SYSLOG] cron-job[<pid>]: <line>.
    • The exit code stays that of the command.
    • With MAILTO set in the crontab file, it only runs the command, and cron mails the output as before. MAILTO="", which turns the mail off, sends the output to syslog.
    • Without syslog-ng (base, base-app, unless enabled), the output stays with cron, as before. For @reboot jobs it waits up to 10 seconds for the socket of syslog-ng if supervisord starts it.
  • Docs: docs/customization.md#cron-jobs (where the output goes, MAILTO, crontab files of your own), docs/known-issues.md (crontab files of your own still mail), docs/environment-variables.md (LOG_STDOUT), docs/images/php.md.
  • make generate.

Changes in behaviour

  • In the Debian and Ubuntu images, the output of jobs from docker-cronjob goes to the container log instead of to cron's mail. Where a mail server runs, as Postfix in the -dev images, the user of the job no longer gets it in its mailbox, unless the crontab sets MAILTO.
  • Crontab files of your own, e.g. in /etc/cron.d, are unchanged.

Tests

  • BaseChecks::testDockerCronjobShellLeavesTheOutputToCronWithMailto: with MAILTO, the script prints the output of the command and keeps its exit code (3).
  • BaseChecks::testDockerCronjobShellSendsTheOutputToSyslog: without MAILTO, the output reaches the container log as cron-job[<pid>]: … and the script prints nothing, with exit code 3. In images without syslog-ng, the output stays on stdout.
  • ContainerEnvironmentChecks::testCronJobOutputReachesTheFileFromTheEnvironment: a job from docker-cronjob (hook 70-image-test-cron.sh) writes a line to stdout and one to stderr; both reach the file of LOG_STDOUT. Only in the Debian and Ubuntu images that start cron.
  • All three fail on the published images, which have no docker-cronjob-shell.

How it was verified

  • Checks of ci/: PHPUnit of ci/ (341 tests) and PHPStan pass.
  • Image tests of php-nginx:8.5, php-nginx:8.5-alpine and base:ubuntu-22.04, built from the published images with the two scripts copied in: the new tests pass.
    • The other failures in that run come from changes on master after those images were built (healthcheck, cli, PHP-FPM logs), not from this change. The CI runs the tests on images built from this branch.
  • By hand, in php-nginx:8.5 with the scripts:
    • docker-cronjob '* * * * * application echo PLAIN-JOB' 'MAILTO=root' '* * * * * application echo MAILTO-JOB': after a minute the container log shows [SYSLOG] cron-job[103]: PLAIN-JOB.
    • For the second job, cron itself logs (CRON) info (No MTA installed, discarding output), so with MAILTO the output went to cron's mail as before.

…ntainer log

Cron in Debian and Ubuntu mails the output of a job and discards it where no
mail server runs, so the output of the jobs that docker-cronjob adds was lost.
docker-cronjob now begins /etc/cron.d/webdevops-docker with
SHELL=/usr/local/bin/docker-cronjob-shell, which runs the command with /bin/sh
and sends its output to syslog, from where syslog-ng writes it to the container
log. With MAILTO set in the crontab file, the script only runs the command and
cron mails the output as before; without syslog-ng, the output stays with cron.
Kanti added a commit that referenced this pull request Nov 23, 2026
The output of the cron jobs of docker-cronjob changes how cron behaves in
Debian and Ubuntu (no mail), so it moves to #667. A new image test checks that
without LOG_STDOUT and LOG_STDERR the output of the services stays in the
container log.
@Kanti
Kanti added this pull request to stack #668 November 23, 2026 08:18
# Conflicts:
#	docker/base/ubuntu-22.04/conf/bin/usr-bin/docker-cronjob
#	docs/environment-variables.md
@sonarqubecloud

Copy link
Copy Markdown

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