Bug #2462
cron resources default behaviour with no periods seems potentially dangerous
| Status: | Closed | Start date: | 07/29/2009 | |
|---|---|---|---|---|
| Priority: | Normal | Due date: | ||
| Assignee: | % Done: | 0% | ||
| Category: | cron | |||
| Target version: | - | |||
| Affected Puppet version: | 0.24.8 | Branch: | ||
| Keywords: | cronfixit customer | |||
Description
As per http://reductivelabs.com/trac/puppet/wiki/TypeReference#cron
“cron
Installs and manages cron jobs. All fields except the command and the user are optional, although specifying no periodic fields would result in the command being executed every minute. While the name of the cron job is not part of the actual job, it is used by Puppet to store and retrieve it."
I think this behaviour is dangerous as it means that default behaviour is a to run a minutely job. That means that if the period fields are not specified by mistake the effect will be to generate very frequent cron activity.
I used to configure my cron jobs like this:
cron {
'minutely_script':
command => '/path/to/minutely/script',
ensure => present,
hour => '*',
minute => '*',
}
However this generates extra logging, making it look like the configuration is incorrect (or not expected):
Wed Jul 29 15:45:17 +0200 2009 //Node[dc01mdb-01.mydomain.com]/s_db/s_db::config/Cron[db_config]/hour (notice): defined ‘hour’ as ‘’ Wed Jul 29 15:45:19 +0200 2009 //Node[dc01mdb-01.mydomain.com]/s_db/s_db::cron/Cron[log_processlist]/minute (notice): defined ‘minute’ as ‘’ Wed Jul 29 15:45:19 +0200 2009 //Node[dc01mdb-01.mydomain.com]/s_db/s_db::cron/Cron[log_processlist]/hour (notice): defined ‘hour’ as ‘*’
From my point of view the correct cron entries were being created.
A colleague of mine said:
“Nasty, if you forget the timings, you get the worst case of the most frequent run of your job. I would make the arguments required and not optional. Cron jobs that need to run every minute are rare in the real world so that shouldn’t be the default.”
I tend to agree. I would prefer that it’s possible define ‘*’ without getting special notifications, and perhaps even that if no period fields are specified that a warning is generated.
Also the documentation should say that it’s possible to specify ‘*’ for “all values in that period”.
We are using a custom built rpm based on puppet-0.24.8-1 on centos4 and 5.
Related issues
History
#1
Updated by Mark Plaksin almost 4 years ago
We’ve definitely been bitten by the default being minutely. I’m not sure what a good default would be unless it just complains when the minute is not specified.
#2
Updated by Simon Mudd almost 4 years ago
I think there are 2 issues here.
Puppet currently complains if I explicitly use ‘’ as a value. It’s not mentioned in the documentation though it seems to work. I’d prefer this to be documented more clearly and to NOT get a warning when using it. By all means provide a different value if that’s really needed, but I think most people know what ‘’ means in cron.¶
Current default behaviour to run minutely jobs could be dangerous. I’d prefer a warning and nothing to happen if no periods are defined at all. That’s safer.¶
#3
Updated by Luke Kanies almost 4 years ago
Simon Mudd wrote:
I think there are 2 issues here.
Puppet currently complains if I explicitly use ‘’ as a value. It’s not mentioned in the documentation though it seems to work. I’d prefer this to be documented more clearly and to NOT get a warning when using it. By all means provide a different value if that’s really needed, but I think most people know what ‘’ means in cron.¶
That’s a relatively easy fix, but why even bother to specify those?
Current default behaviour to run minutely jobs could be dangerous. I’d prefer a warning and nothing to happen if no periods are defined at all. That’s safer.¶
What about cases where people actually want the cron to run every minute?
I think this is a hard problem, and I’ve generally found that any case where I try to protect users from themselves fails pretty miserably.
#4
Updated by Luke Kanies almost 4 years ago
- Category set to cron
- Status changed from Unreviewed to Needs Decision
#5
Updated by Simon Mudd almost 4 years ago
Hi Luke.
The answer to “why bother” to specify these is simple: make the configuration explicit, not implicit. It’s much easier to not spot a mistake in a configuration when an action is not SPECIFICALLY mentioned. That’s what makes me uneasy.
Most cron jobs do NOT run every minute, though there are some that might do (and I was configuring such a job), therefore to have the default behaviour to run every minute seems not to be ideal.
If you want to run jobs every minute then as I suggested allow that and also DO NOT complain about explicitly using ‘*’ when specifying the hour or minute.
Again maybe this is just an issue about clearer documentation for this type of resource, and the edge cases.
The current message is not very helpful:
Wed Jul 29 15:45:19 +0200 2009 //Node[dc01mdb-01.mydomain.com]/s_db/s_db::cron/Cron[log_processlist]/hour (notice): defined ‘hour’ as ‘*’
If this is not needed then say so:
Wed Jul 29 15:45:19 +0200 2009 //Node[dc01mdb-01.mydomain.com]/s_db/s_db::cron/Cron[log_processlist]/hour (notice): defined ‘hour’ as ‘’ unnecessarily. Please remove the hour => ‘’ entry as this is the behaviour if not specified.
I’d still prefer a clearer way to explicitly specify minutely jobs.
#6
Updated by Luke Kanies almost 4 years ago
So what do you recommend as the actual behaviour here? Should the minute just default to ‘0’ or something?
And I’d certainly accept a patch that treated ‘*’ as absent, but that seems like mostly a documentation problem.
#7
Updated by Marcin Deranek about 3 years ago
I believe this is more about documenting default behavior when user does not specify any schedule. There are some gotchas though.. Currently minutely/hourly/daily etc. is not always assumed (http://projects.reductivelabs.com/issues/1724) which means that behavior is not consistent. I believe the right thing should be: assume ‘’ if parameter is omitted (in any case). Another gotcha is that specifying ‘’ trigger constant update of cronjob eg.
[root@mc01admapp-01 tmp]# puppet -v test.pp notice: //Cron[test_cronjob]/minute: defined ‘minute’ as ‘’ [root@mc01admapp-01 tmp]# puppet -v test.pp notice: //Cron[test_cronjob]/minute: defined ‘minute’ as ‘’
[root@mc01admapp-01 tmp]# cat test.pp cron { “test_cronjob”:
command => "date > /dev/null 2>&1",
minute => '*',
}
whereas anything else it does not:
[root@mc01admapp-01 tmp]# puppet -v test.pp notice: //Cron[test_cronjob]/minute: defined ‘minute’ as ‘*/1’ [root@mc01admapp-01 tmp]# puppet -v test.pp [root@mc01admapp-01 tmp]#
[root@mc01admapp-01 tmp]# cat test.pp cron { “test_cronjob”:
command => "date > /dev/null 2>&1",
minute => '*/1',
}
#8
Updated by James Turnbull over 2 years ago
- Assignee set to Nigel Kersten
#9
Updated by Nigel Kersten over 2 years ago
- Status changed from Needs Decision to Accepted
- Assignee deleted (
Nigel Kersten) - Keywords set to cronfixit
Minute should be required rather than optional, to prevent this exact case.
#10
Updated by Zach Leslie about 2 years ago
The documentation for the cron type looks to have been updated. The second sentence notes that leaving period fields blank would result in the command being run every minute. See here for more information:
http://docs.puppetlabs.com/references/stable/type.html#cron
Also, since the default value for each period field of cron itself is *, I would expect entering no periods at all would assume the default values for cron and indeed run the command every minute. Only in the event of specifying a period should the period be changed from default. In my opinion, the current behavior is more logical and preferred.
#11
Updated by James Turnbull about 2 years ago
- Status changed from Accepted to Needs Decision
- Assignee set to Nigel Kersten
See support URL update.
#12
Updated by Nigel Kersten about 2 years ago
- Status changed from Needs Decision to Closed
I’m convinced Zach.
#13
Updated by Charlie Sharpsteen 2 months ago
- Keywords changed from cronfixit to cronfixit customer