Skip to content

Commit

Permalink
Add systemd_randomizeddelaysec
Browse files Browse the repository at this point in the history
Allow configuration of the RandomizedDelaySec parameter of the systemd
timer, which allows randomizing Puppet runs in a way that lets the
administrator see exact moment of the next Puppet run. There's no
incompatibility between Puppet's internal splay and this, but both
probably shouldn't be used together.
  • Loading branch information
jcharaoui authored and mmoll committed Apr 7, 2018
1 parent 5d0f25a commit 98aa874
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions manifests/agent/service/systemd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
default => $::puppet::systemd_cmd,
}

$randomizeddelaysec = $::puppet::systemd_randomizeddelaysec

file { "/etc/systemd/system/${::puppet::systemd_unit_name}.timer":
content => template('puppet/agent/systemd.puppet-run.timer.erb'),
notify => [
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
# $systemd_cmd:: Specify command to launch when runmode is
# set 'systemd.timer'.
#
# $systemd_randomizeddelaysec:: Adds a random delay between 0 and this value
# (in seconds) to the timer. Only relevant when
# runmode is 'systemd.timer'.
#
# $show_diff:: Show and report changed files with diff output
#
# $module_repository:: Use a different puppet module repository
Expand Down Expand Up @@ -582,6 +586,7 @@
Array[Enum['cron', 'service', 'systemd.timer', 'none']] $unavailable_runmodes = $puppet::params::unavailable_runmodes,
Optional[String] $cron_cmd = $puppet::params::cron_cmd,
Optional[String] $systemd_cmd = $puppet::params::systemd_cmd,
Integer[0] $systemd_randomizeddelaysec = $puppet::params::systemd_randomizeddelaysec,
Boolean $agent_noop = $puppet::params::agent_noop,
Boolean $show_diff = $puppet::params::show_diff,
Optional[Stdlib::HTTPUrl] $module_repository = $puppet::params::module_repository,
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
$aio_package = ($::osfamily == 'Windows' or $::rubysitedir =~ /\/opt\/puppetlabs\/puppet/)
$deb_naio_package = ($::osfamily == 'Debian')

$systemd_randomizeddelaysec = 0

case $::osfamily {
'Windows' : {
# Windows prefixes normal paths with the Data Directory's path and leaves 'puppet' off the end
Expand Down
3 changes: 3 additions & 0 deletions spec/classes/puppet_agent_service_systemd_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@
should contain_file('/etc/systemd/system/puppet-run.timer').
with_content(/.*OnCalendar\=\*-\*-\* \*\:10,40:00.*/)

should contain_file('/etc/systemd/system/puppet-run.timer').
with_content(/^RandomizedDelaySec\=0$/)

should contain_file('/etc/systemd/system/puppet-run.service').
with_content(/.*ExecStart=#{bindir}\/puppet agent --config #{confdir}\/puppet.conf --onetime --no-daemonize.*/)

Expand Down
1 change: 1 addition & 0 deletions templates/agent/systemd.puppet-run.timer.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Description=Systemd Timer for Puppet Agent
[Timer]
OnCalendar=*-*-* <%= Array(@times[0]).join(',') %>:<%= Array(@times[1]).join(',') %>:00
Persistent=true
RandomizedDelaySec=<%= @randomizeddelaysec %>

[Install]
WantedBy=timers.target

0 comments on commit 98aa874

Please sign in to comment.