Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 491520 - sys-process/cronbase: run-crons should not end with a zero exit code when any called script has failed
Summary: sys-process/cronbase: run-crons should not end with a zero exit code when any...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: All Linux
: Normal normal (vote)
Assignee: Cron Team
URL:
Whiteboard:
Keywords: PATCH
Depends on:
Blocks:
 
Reported: 2013-11-17 20:06 UTC by Thomas Deutschmann (RETIRED)
Modified: 2015-07-22 07:12 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
indicate script errors with exit code (indicate-script-errors-with-exit-code.patch,744 bytes, patch)
2013-11-17 20:08 UTC, Thomas Deutschmann (RETIRED)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Deutschmann (RETIRED) gentoo-dev 2013-11-17 20:06:07 UTC
"/usr/sbin/run-crons" will be used in "/etc/crontab" from "sys-process/fcron[system-crontab]" (last tested with "fcron-3.1.2-r2") to call the scripts within "/etc/cron.{hourly,daily,weekly,monthly}".

Currently, there is no way to detect a failure. For example if "/etc/cron.hourly/foo" will fail (=end with non-zero exit code) you won't notice.

Solutions like "run-parts" from "sys-apps/debianutils" will end with a non-zero exit code when any executed script has failed.

The attached patch would add the same functionality to "run-crons".
Comment 1 Thomas Deutschmann (RETIRED) gentoo-dev 2013-11-17 20:08:34 UTC
Created attachment 363450 [details, diff]
indicate script errors with exit code

The attached patch will set a non-zero exit code when a called script will fail, so "run-crons" will indicate a problem with the exit code.
Comment 2 SpanKY gentoo-dev 2015-07-21 09:40:52 UTC
what is this good for exactly ?
Comment 3 Thomas Deutschmann (RETIRED) gentoo-dev 2015-07-21 10:08:25 UTC
Thought that comment #0 was clear about that:

When a cronjob fails it should indicate that failure using exit codes. This allows cron to pick up this information and react based on user's settings.

Currently we don't honor exit codes from scripts in "/etc/cron.{hourly,daily,weekly,monthly}". So any cronjob which is installed into one of these folders and which is failing will be "under the radar" - the user won't be notified by cron.

The patch will change that:

1. We will now honor exit codes. That will allow cron to report errors
   (if the user don't want that, the user can always turn that off) for
   failing scripts in "/etc/cron.{hourly,daily,weekly,monthly}".


2. If you check other distributions like RHEL or Debian you will notice that
   these distributions are already honoring exit codes from scripts in
   "/etc/cron.{hourly,daily,weekly,monthly}". So this change will make sure
   that Gentoo keeps up with Linux' defaults.
Comment 4 SpanKY gentoo-dev 2015-07-22 07:10:57 UTC
(In reply to Thomas D. from comment #3)

the confusion is that your patch doesn't really achieve your stated goals.  when run-crons exits non-zero, an e-mail will be generated saying just that: run-crons exited non-zero.  but it won't tell you which script exactly failed.  remember that any invocation of `run-crons` is allowed to run any of the /etc/cron.*/* scripts.

i've updated run-crons to exit non-zero but also utilize syslog with the full name of the failing script:
Jul 22 03:02:10 [run-crons] CMD (/etc/cron.hourly/foo) failed with exit status 1

the generated e-mail is still mostly useless, but that can be handled in bug 540274.
Comment 5 SpanKY gentoo-dev 2015-07-22 07:12:22 UTC
should be all set now in the tree; thanks for the report!

Commit message: When any script fails, log the failure explicitly in case the job itself produced no output, and exit non-zero so higher levels can detect and take action
http://sources.gentoo.org/sys-process/cronbase/cronbase-0.3.5.ebuild?rev=1.1
http://sources.gentoo.org/sys-process/cronbase/files/run-crons-0.3.5?rev=1.1