#887035 cron: Logging to STDOUT when in foreground mode

Package:
cron
Source:
cron
Description:
process scheduling daemon
Submitter:
Greek
Date:
2024-02-29 14:45:03 UTC
Severity:
wishlist
Tags:
#887035#5
Date:
2018-01-12 17:41:28 UTC
From:
To:
Dear Maintainer,

it makes sense to me to Log output to stdout, when cron is executed in
foreground mode using the -f argument.
This can be especially helpful in containerized environments (LXC,
Docker), where a syslog facility is most of the times not available, and
the logging can be handled with a simple redirect.

I have included a patch, which implements this functionality.
NOTE: This patch also incorporates the fix for Bug#887014!

If you need any more info/help, please do not hesitate to contact me (or
reply to this bug report).
--- /usr/bin/editor:
/bin/nano
--- /usr/bin/crontab: -rwxr-sr-x 1 root crontab 36008 Jun 11  2015 /usr/bin/crontab
--- /var/spool/cron: drwxr-xr-x 3 root root 4 Jan 12 13:58 /var/spool/cron
--- /var/spool/cron/crontabs: drwx-wx--T 2 root crontab 2 Jun 11  2015 /var/spool/cron/crontabs
--- /etc/cron.d: drwxr-xr-x 2 root root 4 Jan 12 13:58 /etc/cron.d
--- /etc/cron.daily: drwxr-xr-x 2 root root 11 Jan 12 13:58 /etc/cron.daily
--- /etc/cron.hourly: drwxr-xr-x 2 root root 3 Jan 12 13:58 /etc/cron.hourly
--- /etc/cron.monthly: drwxr-xr-x 2 root root 4 Jan 12 13:58 /etc/cron.monthly
--- /etc/cron.weekly: drwxr-xr-x 2 root root 5 Jan 12 13:58 /etc/cron.weekly
#887035#10
Date:
2021-01-28 17:38:00 UTC
From:
To:
For the use case of containerized environments BusyBox already provides
a cron applet with custom logging capabilities:

busybox crond -f -L /dev/stdout

#887035#15
Date:
2022-07-22 13:59:17 UTC
From:
To:
Instead of patching cron, an easy way to get cron output to stdout is
to:

* rebuild it with debugging enabled:

      $ apt-get source cron
      $ apt-get build-dep cron
      $ cd cron-3.0pl1
      $ DEB_BUILD_OPTIONS=debug dpkg-buildpackage -rfakeroot

* use the undocumented `-x` option of Debian's cron to start it:

       # cron -f -L 15 -x misc

  (I found the `misc` debug log the most suiting)

* wrap the whole thing to redirect stderr to stdout:

      $ cat run-cron
      #!/bin/sh
      exec cron -f -L 15 -x misc 2>&1

@Georges Khaznadar : what do you think about:

1. enabling debugging by default?
2. documenting `-x` ?

If Debian would enable the "debbugging feature" of its cron by default,
then this would add this overhead in a few places:

    if ( (DebugFlags & (mask) )  ) printf message;

Since DebugFlags is 0 by default, this will ad an overhead of about two
machine instructions I guess to a few places, which is a neglible
waste/slowdown IMHO.

With the "debugging feature" enabled Debian's cron will gain the very
nice features:

a) for the sysadmin to be able to debug what cron is doing and why and
b) use the sysadmin being able to use Debian's cron in docker and kubernetes.

IMHO a huge gain that costs nothing.

?
*t
--- /usr/bin/editor:
/usr/bin/vim.gtk3
--- /usr/bin/crontab: -rwxr-sr-x 1 root crontab 43568 Feb 22 2021 /usr/bin/crontab
--- /var/spool/cron: drwxr-xr-x 3 root root 4096 Apr 10 2021 /var/spool/cron
--- /var/spool/cron/crontabs: drwx-wx--T 2 root crontab 4096 Feb 22 2021 /var/spool/cron/crontabs
--- /etc/cron.d: drwxr-xr-x 2 root root 4096 Jul 22 15:03 /etc/cron.d
--- /etc/cron.daily: drwxr-xr-x 2 root root 4096 Jul 11 09:33 /etc/cron.daily
--- /etc/cron.hourly: drwxr-xr-x 2 root root 4096 Apr 10 2021 /etc/cron.hourly
--- /etc/cron.monthly: drwxr-xr-x 2 root root 4096 Apr 10 2021 /etc/cron.monthly
--- /etc/cron.weekly: drwxr-xr-x 2 root root 4096 Apr 10 2021 /etc/cron.weekly
#887035#20
Date:
2022-07-22 17:09:40 UTC
From:
To:
Hello Tomas,

I am discovering the heap of unattended bug reports for a few weeks,
since I began to maintain cron. Thank you for warming up again Bug#887035.

Would it seem reasonable, for your needs, to find two separate binary
packages in Debian, "cron" and let us say, "cron-debug"? Both package
would be built from the same source, the first one with no special
build parameter, the second one with debugging activated (and output to
stdout activated by the switch -f)?

In such a case, you would install "cron-debug", and the sript cron-start
which you suggested might be simpler:

```
#!/bin/sh
exec cron -f -L 15
```

Best regards,			Georges.

Tomas Pospisek a écrit :

#887035#25
Date:
2022-07-23 07:21:39 UTC
From:
To:
If anybody wants to use Greek's patch (see [1] and [2]) then I'm attaching my
version of it adapted to cron 3.0pl1-137 (the version in Debian bullseye).

It comes in two parts: one is the patch and one is
cron-3.0pl1/debian/patches/log-to-stdout-when-in-foreground to satisfy
the Debian build infrastructure.

Use the patch like this to build a new, patched cron package:

    apt-get source cron
    sudo apt-get build-dep cron
    patch -p0 < cron-syslog-fix-and-foreground-stdout.for-new-cron.debianized.patch
    cp log-to-stdout-when-in-foreground cron-3.0pl1/debian/patches
    cd cron-3.0pl1 && dpkg-buildpackage -rfakeroot

*t

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=887035#5
[2] https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=887035;filename=cron-syslog-fix-and-foreground-stdout.patch;msg=5
--- /usr/bin/editor:
/usr/bin/vim.gtk3
--- /usr/bin/crontab: -rwxr-sr-x 1 root crontab 43568 Feb 22 2021 /usr/bin/crontab
--- /var/spool/cron: drwxr-xr-x 3 root root 4096 Apr 10 2021 /var/spool/cron
--- /var/spool/cron/crontabs: drwx-wx--T 2 root crontab 4096 Feb 22 2021 /var/spool/cron/crontabs
--- /etc/cron.d: drwxr-xr-x 2 root root 4096 Jul 22 15:03 /etc/cron.d
--- /etc/cron.daily: drwxr-xr-x 2 root root 4096 Jul 11 09:33 /etc/cron.daily
--- /etc/cron.hourly: drwxr-xr-x 2 root root 4096 Apr 10 2021 /etc/cron.hourly
--- /etc/cron.monthly: drwxr-xr-x 2 root root 4096 Apr 10 2021 /etc/cron.monthly
--- /etc/cron.weekly: drwxr-xr-x 2 root root 4096 Apr 10 2021 /etc/cron.weekly
#887035#30
Date:
2022-07-23 07:07:23 UTC
From:
To:
Hello Georges,

* yes, having a separate package would be fine

* in case you want to go with a separate package than I'd suggest
   `cron-log-to-stderr` as the name because that makes it explicit what
   that package is about.

* however why not keep it in one single package and just make the debug
   feature available?

* as is the `-f` switch will *not* activate output to STDOUT. The patch
   provided by `Greek` [1] does *not* make `-f` log to STDOUT (instead the
   main function of the patch is to add the `priority` parameter to the
   `log_it` function that does the logging to STDERR and to syslog).

* the command line option that switches on logging to STDERR is
   `-x what_to_log`.

Again, I'd argue to make the `-x` aka "debugging output" *feature*
available by default (it will *not* make cron log to STDERR by default.
That needs to be done explicitly by supplying the `-x` switch) and
continue with a single package. It there any technical reason why the
"debugging output" *feature* should not be available?

Thanks a lot for caring about this issue!
*t

[1] https://bugs.debian.org/cgi-bin/bugreport.cgi?att=1;bug=887035;filename=cron-syslog-fix-and-foreground-stdout.patch;msg=5

(I've snipped off the rest of the toplevel posting.)

#887035#35
Date:
2022-07-24 11:27:43 UTC
From:
To:
Hi Tomas,

two remarks:

1) most of Greek's patches which you adapted is about making cron
   installable without the package syslog. Were are the parts about
   "log-to-stdout-when-in-foreground"? I see that one patch modifies
   debian/patches/series, mentioning the file
   log-to-stdout-when-in-foreground, but that file is provided nowhere
   by the set of patches. By the way, do you know who is "Greek"? She or
   he did not reply to questions which I submitted about Bug#887014 ...
   Is "Greek" a pseudonyme of yours?

2) I shall not patch cron 3.0pl1-137. You can do it if you want,
   for your own usage, of course. If I modify debian's cron package, I
   must do it in the testing distribution, so please propose patches
   targetting at least cron 3.0pl1-147. Then, if the modification you
   are wishing is accepted in debian/testing, I can create a backport to
   use in debian/bullseye later, for example a release such as cron
   3.0pl1-149~bpo11+1, to be published in bullseye-backports.

Best regards,			Georges.
Tomas Pospisek a écrit :

#887035#40
Date:
2022-07-24 13:23:19 UTC
From:
To:
Hi Georges,

first off: this patch is completely irrelevant IMHO. We should not be
discussing it. What's relevant is [1].

That is what it claims but not what it does AFAICS. What it does is
adapt the `log_it` function so that it takes a `priority` parameter. But
again. This patch is irrelevant. [1] is relevant IMO.

It's at [2]. But it's irrelevant. [1] is relevant.

Again see [2]. But it's irrelevant. [1] is relevant.

No

It's been 4 years since this bug has been filed so "Greek" might have
moved on since.

No

Ack. However I do not want that patch to be included because as I said as
far as I can see it does *not* activate output to STDOUT, contrary to what
the origianl message by "Greek" claims. That patch is irrelevant, I have
only posted it in case somebody is interested in using it. But I am
*not* interested in it. I am interested in [1] only.

Thanks!
*t

[1] - enable debugging logs: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=887035#15/
[2] - debian/patches: https://bugs.debian.org/cgi-bin/bugreport.cgi?att=2;bug=887035;filename=log-to-stdout-when-in-foreground;msg=25

#887035#45
Date:
2022-12-13 23:43:40 UTC
From:
To:
Dockerfile:
FROM debian

RUN apt-get update && apt-get install -y busybox

CMD ["bash"]

$ docker build -t test .
$ docker run --rm -it test
# busybox crond -f
crond: applet not found

Can you clarify how one can use busybox’s crond in a containerized environment?

Thank you,
Nick R.

#887035#50
Date:
2024-02-29 12:51:39 UTC
From:
To:
Hello Tomas,

with the current version of cron in trixie,

- the build was done with debugging active
- man cron provides information about the `-x` flag.

So, I close the bug report. Please feel free to reopen it when
necessary, or send another bug report if something doe not fulfill your
needs.

Best regards,			Georges.

#887035#55
Date:
2024-02-29 12:51:39 UTC
From:
To:
Hello Tomas,

with the current version of cron in trixie,

- the build was done with debugging active
- man cron provides information about the `-x` flag.

So, I close the bug report. Please feel free to reopen it when
necessary, or send another bug report if something doe not fulfill your
needs.

Best regards,			Georges.

#887035#60
Date:
2024-02-29 13:58:54 UTC
From:
To:
Nice, thanks a lot Georges!!!
*t