Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add parameter to manage default target #270

Merged
merged 1 commit into from
May 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ systemd::network{'eth0.network':

### Services

The default target is managed via the `default_target` parameter. If this is left at its default value (`undef`), the default-target will be unmanaged by puppet.

Systemd provides multiple services. Currently you can manage `systemd-resolved`,
`systemd-timesyncd`, `systemd-networkd`, `systemd-journald`, `systemd-coredump`
and `systemd-logind`
Expand Down
18 changes: 18 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#
# @api public
#
# @param default_target
# The default systemd boot target, unmanaged if set to undef.
#
# @param service_limits
# May be passed a resource hash suitable for passing directly into the
# ``create_resources()`` function as called on ``systemd::service_limits``
Expand Down Expand Up @@ -160,6 +163,7 @@
# Add --backtrace to systemd-coredump call systemd-coredump@.service unit
#
class systemd (
Optional[Pattern['^.+\.target$']] $default_target = undef,
Hash[String,String] $accounting = {},
Hash[String[1],Hash[String[1], Any]] $service_limits = {},
Hash[String[1],Hash[String[1], Any]] $networks = {},
Expand Down Expand Up @@ -210,6 +214,20 @@
) {
contain systemd::install

if $default_target {
$target = shell_escape($default_target)
service { $target:
ensure => 'running',
enable => true,
}

exec { "systemctl set-default ${target}":
command => "systemctl set-default ${target}",
unless => "test $(systemctl get-default) = ${target}",
path => $facts['path'],
}
}

$service_limits.each |$service_limit, $service_limit_data| {
systemd::service_limits { $service_limit:
* => $service_limit_data,
Expand Down
12 changes: 12 additions & 0 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
it { is_expected.not_to create_service('systemd-timesyncd') }
it { is_expected.not_to contain_package('systemd-resolved') }
it { is_expected.not_to contain_class('systemd::coredump') }
it { is_expected.not_to contain_exec('systemctl set-default multi-user.target') }

context 'when enabling resolved and networkd' do
let(:params) do
Expand Down Expand Up @@ -181,6 +182,17 @@
}
end

context 'with alternate target' do
let(:params) do
{
default_target: 'example.target',
}
end

it { is_expected.to contain_exec('systemctl set-default example.target') }
it { is_expected.to contain_service('example.target').with_enable(true).with_ensure('running') }
end

context 'when enabling timesyncd' do
let(:params) do
{
Expand Down