Skip to content

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

Draft
Kanti wants to merge 8 commits into
bugfix/logs-to-container-logfrom
bugfix/cron-job-output
Draft

Kanti wants to merge 8 commits into
bugfix/logs-to-container-logfrom
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. It builds on #657, whose branch is its base (stack: #657 → this → #658): the split of syslog by level comes from there.

Update after the review of #657

The output of cron jobs is now the same in Debian and Alpine: stdout to the stdout of the container, stderr to its stderr, each line tagged cron-job[<pid>].

  • Alpine: docker-cronjob writes SHELL=/usr/local/bin/docker-cronjob-shell into /etc/crontabs/<user> before the first job it adds there; BusyBox crond takes SHELL= for the lines below it (checked with BusyBox 1.37.0). The lines above it, such as those of Alpine in the crontab of root, keep /bin/sh. Before, crond passed the output on untagged.
  • docker-cronjob-shell: stdout goes to syslog at the level info, stderr at the level err; with the split of [BUGFIX] Send the remaining logs of the services to the container log #657, syslog-ng writes them to /docker.stdout and /docker.stderr. Before, both went to stdout together.
  • Alpine and MAILTO: docker-cronjob in Alpine takes only job lines, as before, and BusyBox crond does not pass MAILTO on to the job, so in Alpine the output always goes to syslog.
  • Tests: BaseChecks::testDockerCronjobShellSendsTheOutputToSyslog checks the stdout line on the stdout of the container and the stderr line on its stderr, each only there; the case for images without syslog-ng is gone (every image starts it since [!!!][TASK] Stop building bootstrap, base, base-app and dockerfile-build-env, and run the CI on the runners #662). ContainerEnvironmentChecks::testCronJobOutputReachesTheFilesFromTheEnvironment (renamed) runs in Alpine too and checks the stdout line in the file of LOG_STDOUT and the stderr line in that of LOG_STDERR, each only there.
  • Verified: all image tests of php:8.4 and php:8.4-alpine on the published images with the conf/ of this branch copied over: the cron tests pass in both. The only failures come from the overlay itself (build scripts and installers copied back in) and, in Alpine, from installs through apk that the network of the test machine refuses.

The text below describes the pull request before that update.

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 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, 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, LOG_STDERR), docs/images/php.md.
  • make generate.

Changes in behaviour

  • In the Debian 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.
  • In the Alpine images, the output of jobs from docker-cronjob goes through syslog, tagged cron-job[<pid>].
  • 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, stdout and stderr, and keeps its exit code (3).
  • BaseChecks::testDockerCronjobShellSendsTheOutputToSyslog: see the update above.
  • ContainerEnvironmentChecks::testCronJobOutputReachesTheFilesFromTheEnvironment: see the update above.
  • They fail on the published images, which have no docker-cronjob-shell.

How it was verified

  • Checks of ci/: GrumPHP passes except composer audit, which reports two advisories of symfony/expression-language published on 2026-11-25; they affect master as well.
  • Image tests: see the update above.
  • By hand, in php-nginx:8.5 with the scripts, before the update:
    • 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.
  • By hand, BusyBox crond 1.37.0 in php:8.4-alpine: a crontab with a job, then SHELL=<script>, then a job: only the second job ran through the script; MAILTO in the crontab did not reach the environment of the job.

…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

@Kanti
Kanti removed this pull request from stack #668 November 26, 2026 10:03
@Kanti
Kanti changed the base branch from master to bugfix/logs-to-container-log November 26, 2026 10:03
@Kanti
Kanti added this pull request to stack #677 November 26, 2026 10:03
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