Skip to content

Commit

Permalink
Revert "Convert the systemd timer service to camptocamp/systemd"
Browse files Browse the repository at this point in the history
This reverts commit 4302973, except the
dependency bits. It's also updated to be lint clean.

The reason to revert this is that the integrated daemon reload in
systemd::timer leads to dependency cycles in the Katello scenario.
  • Loading branch information
ekohl authored and mmoll committed May 5, 2020
1 parent 32b4e55 commit 904e51b
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 26 deletions.
79 changes: 63 additions & 16 deletions manifests/agent/service/systemd.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,69 @@
Optional[Integer[0,59]] $minute = undef,
) {
unless $puppet::runmode == 'unmanaged' or 'systemd.timer' in $puppet::unavailable_runmodes {
# Use the same times as for cron
$times = extlib::ip_to_cron($puppet::runinterval)

# But only if they are not explicitly specified
$_hour = pick($hour, $times[0])
$_minute = pick($minute, $times[1])

$command = pick($puppet::systemd_cmd, "${puppet::puppet_cmd} agent --config ${puppet::dir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure")
$randomizeddelaysec = $puppet::systemd_randomizeddelaysec

systemd::timer { "${puppet::systemd_unit_name}.timer":
ensure => bool2str($enabled, 'present', 'absent'),
active => $enabled,
enable => $enabled,
timer_content => template('puppet/agent/systemd.puppet-run.timer.erb'),
service_content => template('puppet/agent/systemd.puppet-run.service.erb'),
exec { 'systemctl-daemon-reload-puppet':
refreshonly => true,
path => $::path,
command => 'systemctl daemon-reload',
}

if $enabled {
# Use the same times as for cron
$times = extlib::ip_to_cron($puppet::runinterval)

# But only if they are not explicitly specified
$_hour = pick($hour, $times[0])
$_minute = pick($minute, $times[1])

$command = $puppet::systemd_cmd ? {
undef => "${puppet::puppet_cmd} agent --config ${puppet::dir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure",
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 => [
Exec['systemctl-daemon-reload-puppet'],
Service['puppet-run.timer'],
],
}

file { "/etc/systemd/system/${puppet::systemd_unit_name}.service":
content => template('puppet/agent/systemd.puppet-run.service.erb'),
notify => Exec['systemctl-daemon-reload-puppet'],
}

service { 'puppet-run.timer':
ensure => running,
provider => 'systemd',
name => "${puppet::systemd_unit_name}.timer",
enable => true,
require => Exec['systemctl-daemon-reload-puppet'],
}
} else {
# Reverse order - stop, delete files, exec
service { 'puppet-run.timer':
ensure => stopped,
provider => 'systemd',
name => "${puppet::systemd_unit_name}.timer",
enable => false,
before => [
File["/etc/systemd/system/${puppet::systemd_unit_name}.timer"],
File["/etc/systemd/system/${puppet::systemd_unit_name}.service"],
],
}

file { "/etc/systemd/system/${puppet::systemd_unit_name}.timer":
ensure => absent,
notify => Exec['systemctl-daemon-reload-puppet'],
}

file { "/etc/systemd/system/${puppet::systemd_unit_name}.service":
ensure => absent,
notify => Exec['systemctl-daemon-reload-puppet'],
}
}
}
}
39 changes: 29 additions & 10 deletions spec/classes/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,15 @@
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
case os
when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/
it do
is_expected.to contain_exec('systemctl-daemon-reload-puppet')
.with_refreshonly(true)
.with_command('systemctl daemon-reload')
end

it do
is_expected.to contain_service('puppet-run.timer')
.with_ensure(false)
.with_ensure(:stopped)
.with_provider('systemd')
.with_name('puppet-run.timer')
.with_enable(false)
Expand All @@ -119,6 +125,7 @@
it { is_expected.not_to contain_service('puppet-run.timer') }
it { is_expected.not_to contain_file('/etc/systemd/system/puppet-run.timer') }
it { is_expected.not_to contain_file('/etc/systemd/system/puppet-run.service') }
it { is_expected.not_to contain_exec('systemctl-daemon-reload-puppet') }
end
end

Expand Down Expand Up @@ -205,7 +212,7 @@
.with_enable('false')
end
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(:stopped) }
it do
is_expected.to contain_cron('puppet')
.with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize")
Expand Down Expand Up @@ -251,7 +258,7 @@
.with_enable('false')
end
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(:stopped) }
it do
is_expected.to contain_cron('puppet')
.with_command("#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize")
Expand Down Expand Up @@ -286,7 +293,7 @@
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(true) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(true) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(:running) }

it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.timer')
Expand All @@ -303,12 +310,18 @@
.with_content(%r{^ExecStart=#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure$})
end

it do
is_expected.to contain_exec('systemctl-daemon-reload-puppet')
.with_refreshonly(true)
.with_command('systemctl daemon-reload')
end

it do
is_expected.to contain_service('puppet-run.timer')
.with_provider('systemd')
.with_ensure(true)
.with_ensure('running')
.with_name('puppet-run.timer')
.with_enable(true)
.with_enable('true')
end
else
it { is_expected.to raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) }
Expand All @@ -329,7 +342,7 @@
it { is_expected.to contain_class('puppet::agent::service::daemon').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::cron').with_enabled(false) }
it { is_expected.to contain_class('puppet::agent::service::systemd').with_enabled(true) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(true) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(:running) }

it do
is_expected.to contain_file('/etc/systemd/system/puppet-run.timer')
Expand All @@ -346,12 +359,18 @@
.with_content(%r{^ExecStart=#{bindir}/puppet agent --config #{confdir}/puppet.conf --onetime --no-daemonize --detailed-exitcode --no-usecacheonfailure$})
end

it do
is_expected.to contain_exec('systemctl-daemon-reload-puppet')
.with_refreshonly(true)
.with_command('systemctl daemon-reload')
end

it do
is_expected.to contain_service('puppet-run.timer')
.with_provider('systemd')
.with_ensure(true)
.with_ensure('running')
.with_name('puppet-run.timer')
.with_enable(true)
.with_enable('true')
end
else
it { is_expected.to raise_error(Puppet::Error, /Runmode of systemd.timer not supported on #{facts[:kernel]} operating systems!/) }
Expand All @@ -373,7 +392,7 @@

case os
when /\Adebian-/, /\A(redhat|centos|scientific)-7/, /\Afedora-/, /\Aubuntu-(16|18)/, /\Aarchlinux-/
it { is_expected.to contain_service('puppet-run.timer').with_ensure(false) }
it { is_expected.to contain_service('puppet-run.timer').with_ensure(:stopped) }
else
it { is_expected.not_to contain_service('puppet-run.timer') }
end
Expand Down

0 comments on commit 904e51b

Please sign in to comment.