14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ All notable changes to this project will be documented in this file.
Each new release typically also includes the latest modulesync defaults.
These should not affect the functionality of the module.

## [v4.1.0](https://github.com/voxpupuli/puppet-systemd/tree/v4.1.0) (2023-03-31)

[Full Changelog](https://github.com/voxpupuli/puppet-systemd/compare/v4.0.1...v4.1.0)

**Implemented enhancements:**

- Expand managed unit entry with User, Group + EnvironmentFile Array [\#323](https://github.com/voxpupuli/puppet-systemd/pull/323) ([ekohl](https://github.com/ekohl))
- Add timer\_entry to manage\_{dropin,unit} [\#322](https://github.com/voxpupuli/puppet-systemd/pull/322) ([ekohl](https://github.com/ekohl))
- add support for {AlmaLinux,Rocky} {8,9} [\#319](https://github.com/voxpupuli/puppet-systemd/pull/319) ([jhoblitt](https://github.com/jhoblitt))

**Fixed bugs:**

- Systemd::Unit::Service: missing User and Group [\#299](https://github.com/voxpupuli/puppet-systemd/issues/299)

## [v4.0.1](https://github.com/voxpupuli/puppet-systemd/tree/v4.0.1) (2023-01-31)

[Full Changelog](https://github.com/voxpupuli/puppet-systemd/compare/v4.0.0...v4.0.1)
Expand Down
45 changes: 43 additions & 2 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
* [`Systemd::Unit::Install`](#Systemd--Unit--Install): Possible keys for the [Install] section of a unit file
* [`Systemd::Unit::Service`](#Systemd--Unit--Service): Possible keys for the [Service] section of a unit file
* [`Systemd::Unit::Service::Exec`](#Systemd--Unit--Service--Exec): Possible strings for ExecStart, ExecStartPrep, ...
* [`Systemd::Unit::Timer`](#Systemd--Unit--Timer): Possible keys for the [Timer] section of a unit file
* [`Systemd::Unit::Unit`](#Systemd--Unit--Unit): Possible keys for the [Unit] section of a unit file

## Classes
Expand Down Expand Up @@ -798,6 +799,7 @@ The following parameters are available in the `systemd::manage_dropin` defined t
* [`unit_entry`](#-systemd--manage_dropin--unit_entry)
* [`service_entry`](#-systemd--manage_dropin--service_entry)
* [`install_entry`](#-systemd--manage_dropin--install_entry)
* [`timer_entry`](#-systemd--manage_dropin--timer_entry)

##### <a name="-systemd--manage_dropin--unit"></a>`unit`

Expand Down Expand Up @@ -909,6 +911,14 @@ key value pairs for [Install] section of the unit file

Default value: `undef`

##### <a name="-systemd--manage_dropin--timer_entry"></a>`timer_entry`

Data type: `Optional[Systemd::Unit::Timer]`

key value pairs for [Timer] section of the unit file

Default value: `undef`

### <a name="systemd--manage_unit"></a>`systemd::manage_unit`

Generate unit file from template
Expand Down Expand Up @@ -955,6 +965,7 @@ The following parameters are available in the `systemd::manage_unit` defined typ
* [`unit_entry`](#-systemd--manage_unit--unit_entry)
* [`service_entry`](#-systemd--manage_unit--service_entry)
* [`install_entry`](#-systemd--manage_unit--install_entry)
* [`timer_entry`](#-systemd--manage_unit--timer_entry)

##### <a name="-systemd--manage_unit--name"></a>`name`

Expand Down Expand Up @@ -1066,10 +1077,12 @@ key value pairs for [Unit] section of the unit file.

##### <a name="-systemd--manage_unit--service_entry"></a>`service_entry`

Data type: `Systemd::Unit::Service`
Data type: `Optional[Systemd::Unit::Service]`

key value pairs for [Service] section of the unit file.

Default value: `undef`

##### <a name="-systemd--manage_unit--install_entry"></a>`install_entry`

Data type: `Optional[Systemd::Unit::Install]`
Expand All @@ -1078,6 +1091,14 @@ key value pairs for [Install] section of the unit file.

Default value: `undef`

##### <a name="-systemd--manage_unit--timer_entry"></a>`timer_entry`

Data type: `Optional[Systemd::Unit::Timer]`

key value pairs for [Timer] section of the unit file

Default value: `undef`

### <a name="systemd--modules_load"></a>`systemd::modules_load`

Creates a modules-load.d drop file
Expand Down Expand Up @@ -2146,6 +2167,8 @@ Alias of

```puppet
Struct[{
Optional['User'] => String[1],
Optional['Group'] => String[1],
Optional['Type'] => Enum['simple', 'exec', 'forking', 'oneshot', 'dbus', 'notify', 'idle'],
Optional['ExitType'] => Enum['main', 'cgroup'],
Optional['RemainAfterExit'] => Boolean,
Expand Down Expand Up @@ -2180,7 +2203,10 @@ Struct[{
Optional['OOMPolicy'] => Enum['continue', 'stop','kill'],
Optional['OOMScoreAdjust'] => Integer[-1000,1000],
Optional['Environment'] => String,
Optional['EnvironmentFile'] => Variant[Stdlib::Unixpath,Pattern[/-\/.*/]],
Optional['EnvironmentFile'] => Variant[
Stdlib::Unixpath,Pattern[/-\/.+/],
Array[Variant[Stdlib::Unixpath,Pattern[/-\/.+/]],1],
],
}]
```

Expand All @@ -2194,6 +2220,21 @@ Possible strings for ExecStart, ExecStartPrep, ...

Alias of `Variant[Enum[''], Pattern[/^[@\-:]*(\+|!|!!)?[@\-:]*\/.*/], Pattern[/^[@\-:]*(\+|!|!!)?[@\-:]*[^\/]*(\s.*)?$/]]`

### <a name="Systemd--Unit--Timer"></a>`Systemd::Unit::Timer`

Possible keys for the [Timer] section of a unit file

* **See also**
* https://www.freedesktop.org/software/systemd/man/systemd.timer.html

Alias of

```puppet
Struct[{
Optional['OnCalendar'] => Variant[String,Array[String,1]],
}]
```

### <a name="Systemd--Unit--Unit"></a>`Systemd::Unit::Unit`

Possible keys for the [Unit] section of a unit file
Expand Down
7 changes: 7 additions & 0 deletions manifests/manage_dropin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# @param unit_entry key value pairs for [Unit] section of the unit file
# @param service_entry key value pairs for [Service] section of the unit file
# @param install_entry key value pairs for [Install] section of the unit file
# @param timer_entry key value pairs for [Timer] section of the unit file
#
define systemd::manage_dropin (
Systemd::Unit $unit,
Expand All @@ -44,7 +45,12 @@
Optional[Systemd::Unit::Install] $install_entry = undef,
Optional[Systemd::Unit::Unit] $unit_entry = undef,
Optional[Systemd::Unit::Service] $service_entry = undef,
Optional[Systemd::Unit::Timer] $timer_entry = undef,
) {
if $timer_entry and $unit !~ Pattern['^[^/]+\.timer'] {
fail("Systemd::Manage_unit[${name}]: timer_entry is only valid for timer units")
}

systemd::dropin_file { $name:
ensure => $ensure,
filename => $filename,
Expand All @@ -61,6 +67,7 @@
'unit_entry' => $unit_entry,
'service_entry' => $service_entry,
'install_entry' => $install_entry,
'timer_entry' => $timer_entry,
}),
}
}
13 changes: 12 additions & 1 deletion manifests/manage_unit.pp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
# @param unit_entry key value pairs for [Unit] section of the unit file.
# @param service_entry key value pairs for [Service] section of the unit file.
# @param install_entry key value pairs for [Install] section of the unit file.
# @param timer_entry key value pairs for [Timer] section of the unit file
#
define systemd::manage_unit (
Enum['present', 'absent'] $ensure = 'present',
Expand All @@ -55,10 +56,19 @@
Boolean $daemon_reload = true,
Optional[Systemd::Unit::Install] $install_entry = undef,
Systemd::Unit::Unit $unit_entry,
Systemd::Unit::Service $service_entry,
Optional[Systemd::Unit::Service] $service_entry = undef,
Optional[Systemd::Unit::Timer] $timer_entry = undef,
) {
assert_type(Systemd::Unit, $name)

if $timer_entry and $name !~ Pattern['^[^/]+\.timer'] {
fail("Systemd::Manage_unit[${name}]: timer_entry is only valid for timer units")
}

if $name =~ Pattern['^[^/]+\.service'] and !$service_entry {
fail("Systemd::Manage_unit[${name}]: service_entry is only required for service units")
}

systemd::unit_file { $name:
ensure => $ensure,
path => $path,
Expand All @@ -75,6 +85,7 @@
'unit_entry' => $unit_entry,
'service_entry' => $service_entry,
'install_entry' => $install_entry,
'timer_entry' => $timer_entry,
}),
}
}
16 changes: 15 additions & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "puppet-systemd",
"version": "4.0.1",
"version": "4.1.0",
"author": "Vox Pupuli",
"summary": "Puppet Systemd module",
"license": "Apache-2.0",
Expand Down Expand Up @@ -62,6 +62,20 @@
"9"
]
},
{
"operatingsystem": "AlmaLinux",
"operatingsystemrelease": [
"8",
"9"
]
},
{
"operatingsystem": "Rocky",
"operatingsystemrelease": [
"8",
"9"
]
},
{
"operatingsystem": "OracleLinux",
"operatingsystemrelease": [
Expand Down
94 changes: 66 additions & 28 deletions spec/defines/manage_dropin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,86 @@

let(:title) { 'foobar.conf' }

context 'drop file chaning Type and resetting ExecStart' do
context 'on a service' do
let(:params) do
{
unit: 'special.service',
service_entry: {
Type: 'oneshot',
ExecStart: ['', '/usr/bin/doit.sh'],
},
}
end

it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__dropin_file('foobar.conf') }
context 'drop file chaning Type and resetting ExecStart' do
let(:params) do
super().merge(
service_entry: {
Type: 'oneshot',
ExecStart: ['', '/usr/bin/doit.sh'],
}
)
end

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^\[Service\]$})
}
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_systemd__dropin_file('foobar.conf') }

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
without_content(%r{^\[Unit\]$})
}
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^\[Service\]$})
}

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
without_content(%r{^\[Install\]$})
}
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
without_content(%r{^\[Unit\]$})
}

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^ExecStart=$})
}
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
without_content(%r{^\[Install\]$})
}

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^ExecStart=/usr/bin/doit.sh$})
}
it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^ExecStart=$})
}

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^ExecStart=/usr/bin/doit.sh$})
}

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^Type=oneshot$})
}
end

context 'with a timer entry' do
let(:params) do
super().merge(
timer_entry: {
'OnCalendar' => 'soon',
}
)
end

it { is_expected.to compile.and_raise_error(%r{timer_entry is only valid for timer units}) }
end
end

context 'on a timer' do
let(:params) do
{
unit: 'special.timer',
timer_entry: {
'OnCalendar' => 'soon',
}
}
end

it { is_expected.to compile.with_all_deps }

it {
is_expected.to contain_systemd__dropin_file('foobar.conf').
with_content(%r{^Type=oneshot$})
with_unit('special.timer').
with_content(%r{^OnCalendar=soon$})
}
end
end
Expand Down
30 changes: 30 additions & 0 deletions spec/defines/manage_unit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,36 @@
is_expected.to contain_systemd__unit_file('foobar.service').
with_content(%r{^Type=oneshot$})
}

context 'with a timer entry' do
let(:params) do
super().merge(timer_entry: { 'OnCalendar' => 'something' })
end

it { is_expected.to compile.and_raise_error(%r{timer_entry is only valid for timer units}) }
end
end

context 'on a timer' do
let(:title) { 'winter.timer' }

let(:params) do
{
unit_entry: {
Description: 'Winter is coming',
},
timer_entry: {
'OnCalendar' => 'soon',
}
}
end

it { is_expected.to compile.with_all_deps }

it {
is_expected.to contain_systemd__unit_file('winter.timer').
with_content(%r{^OnCalendar=soon$})
}
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions spec/type_aliases/systemd_unit_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@

it { is_expected.to allow_value({ 'EnvironmentFile' => '/etc/sysconfig/foo' }) }
it { is_expected.to allow_value({ 'EnvironmentFile' => '-/etc/sysconfig/foo' }) }
it { is_expected.to allow_value({ 'EnvironmentFile' => ['/etc/sysconfig/foo', '-/etc/sysconfig/foo-bar'] }) }
it { is_expected.not_to allow_value({ 'EnvironmentFile' => '-/' }) }
it { is_expected.not_to allow_value({ 'EnvironmentFile' => 'relative-path.sh' }) }
end
Loading