Skip to content

Commit 7ffd620

Browse files
Merge pull request #98 from dwagon/master
Allow full cron specification for minute / hour
2 parents bdc25cd + 0b96284 commit 7ffd620

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

manifests/agent.pp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
# ['templatedir'] - Template dir, if unset it will remove the setting.
2828
# ['configtimeout'] - How long the client should wait for the configuration to be retrieved before considering it a failure
2929
# ['stringify_facts'] - Wether puppet transforms structured facts in strings or no. Defaults to true in puppet < 4, deprecated in puppet >=4 (and will default to false)
30+
# ['cron_hour'] - What hour to run if puppet_run_style is cron
31+
# ['cron_minute'] - What minute to run if puppet_run_style is cron
3032
#
3133
# Actions:
3234
# - Install and configures the puppet agent
@@ -78,6 +80,8 @@
7880
$certname = undef,
7981
$http_proxy_host = undef,
8082
$http_proxy_port = undef,
83+
$cron_hour = '*',
84+
$cron_minute = undef,
8185
) inherits puppet::params {
8286

8387
if ! defined(User[$::puppet::params::puppet_user]) {
@@ -135,18 +139,21 @@
135139
$service_ensure = 'stopped'
136140
$service_enable = false
137141

138-
# Run puppet as a cron - this saves memory and avoids the whole problem
139-
# where puppet locks up for no reason. Also spreads out the run intervals
140-
# more uniformly.
141-
$time1 = fqdn_rand($puppet_run_interval)
142-
$time2 = fqdn_rand($puppet_run_interval) + 30
142+
# Default to every 30 minutes - random around the clock
143+
if $cron_minute == undef {
144+
$time1 = fqdn_rand(30)
145+
$time2 = $time1 + 30
146+
$minute = [ $time1, $time2 ]
147+
}
148+
else {
149+
$minute = $cron_minute
150+
}
143151

144152
cron { 'puppet-client':
145153
command => $puppet_run_command,
146154
user => 'root',
147-
# run twice an hour, at a random minute in order not to collectively stress the puppetmaster
148-
hour => '*',
149-
minute => [ $time1, $time2 ],
155+
hour => $cron_hour,
156+
minute => $minute,
150157
}
151158
}
152159
# Run Puppet through external tooling, like MCollective

spec/classes/puppet_agent_spec.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
:puppet_run_style => 'cron',
5151
:splay => 'true',
5252
:environment => 'production',
53-
:puppet_run_interval => 30,
5453
:puppet_server_port => 8140,
54+
:cron_hour => 5,
55+
:cron_minute => '*/30',
5556
}
5657
end
5758
it{
@@ -69,8 +70,9 @@
6970
)
7071
should contain_cron('puppet-client').with(
7172
:command => '/usr/bin/puppet agent --no-daemonize --onetime --logdest syslog > /dev/null 2>&1',
72-
:user => 'root',
73-
:hour => '*'
73+
:user => 'root',
74+
:hour => '5',
75+
:minute => '*/30'
7476
)
7577
}
7678
end

0 commit comments

Comments
 (0)