Skip to content

Commit 7ecb058

Browse files
authored
Merge pull request #490 from traylenator/mount
Support Mount units for manage_unit or dropin types
2 parents 259c26b + df38742 commit 7ecb058

File tree

8 files changed

+210
-0
lines changed

8 files changed

+210
-0
lines changed

REFERENCE.md

+67
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
* [`Systemd::Unit::Amount`](#Systemd--Unit--Amount): Systemd definition of amount, often bytes or united bytes
6868
* [`Systemd::Unit::AmountOrPercent`](#Systemd--Unit--AmountOrPercent): Systemd definition of amount, often bytes or united bytes
6969
* [`Systemd::Unit::Install`](#Systemd--Unit--Install): Possible keys for the [Install] section of a unit file
70+
* [`Systemd::Unit::Mount`](#Systemd--Unit--Mount): Possible keys for the [Mount] section of a unit file
7071
* [`Systemd::Unit::Path`](#Systemd--Unit--Path): Possible keys for the [Path] section of a unit file
7172
* [`Systemd::Unit::Percent`](#Systemd--Unit--Percent): Systemd definition of a percentage
7273
* [`Systemd::Unit::Service`](#Systemd--Unit--Service): Possible keys for the [Service] section of a unit file
@@ -1031,6 +1032,7 @@ The following parameters are available in the `systemd::manage_dropin` defined t
10311032
* [`timer_entry`](#-systemd--manage_dropin--timer_entry)
10321033
* [`path_entry`](#-systemd--manage_dropin--path_entry)
10331034
* [`socket_entry`](#-systemd--manage_dropin--socket_entry)
1035+
* [`mount_entry`](#-systemd--manage_dropin--mount_entry)
10341036

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

@@ -1174,6 +1176,14 @@ key value pairs for the [Socket] section of the unit file
11741176

11751177
Default value: `undef`
11761178

1179+
##### <a name="-systemd--manage_dropin--mount_entry"></a>`mount_entry`
1180+
1181+
Data type: `Optional[Systemd::Unit::Mount]`
1182+
1183+
key value pairs for the [Mount] section of the unit file
1184+
1185+
Default value: `undef`
1186+
11771187
### <a name="systemd--manage_unit"></a>`systemd::manage_unit`
11781188

11791189
Generate unit file from template
@@ -1251,6 +1261,30 @@ systemd::manage_unit{'arcd@.service':
12511261
}
12521262
```
12531263

1264+
##### Mount a Filesystem and Use for a Service
1265+
1266+
```puppet
1267+
systemd::manage_unit { 'var-lib-sss-db.mount':
1268+
ensure => present,
1269+
unit_entry => {
1270+
'Description' => 'Mount sss tmpfs db',
1271+
},
1272+
mount_entry => {
1273+
'What' => 'tmpfs',
1274+
'Where' => '/var/lib/sss/db',
1275+
'Type' => 'tmpfs',
1276+
'Options' => 'size=300M,mode=0700,uid=sssd,gid=sssd,rootcontext=system_u:object_r:sssd_var_lib_t:s0',
1277+
},
1278+
}
1279+
systemd::manage_dropin { 'tmpfs-db.conf':
1280+
ensure => present,
1281+
unit => 'sssd.service',
1282+
unit_entry => {
1283+
'RequiresMountsFor' => '/var/lib/sss/db',
1284+
},
1285+
}
1286+
```
1287+
12541288
##### Remove a unit file
12551289

12561290
```puppet
@@ -1284,6 +1318,7 @@ The following parameters are available in the `systemd::manage_unit` defined typ
12841318
* [`timer_entry`](#-systemd--manage_unit--timer_entry)
12851319
* [`path_entry`](#-systemd--manage_unit--path_entry)
12861320
* [`socket_entry`](#-systemd--manage_unit--socket_entry)
1321+
* [`mount_entry`](#-systemd--manage_unit--mount_entry)
12871322

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

@@ -1451,6 +1486,14 @@ kev value paors for [Socket] section of the unit file.
14511486

14521487
Default value: `undef`
14531488

1489+
##### <a name="-systemd--manage_unit--mount_entry"></a>`mount_entry`
1490+
1491+
Data type: `Optional[Systemd::Unit::Mount]`
1492+
1493+
kev value pairs for [Mount] section of the unit file.
1494+
1495+
Default value: `undef`
1496+
14541497
### <a name="systemd--modules_load"></a>`systemd::modules_load`
14551498

14561499
Creates a modules-load.d drop file
@@ -2798,6 +2841,30 @@ Struct[{
27982841
}]
27992842
```
28002843

2844+
### <a name="Systemd--Unit--Mount"></a>`Systemd::Unit::Mount`
2845+
2846+
Possible keys for the [Mount] section of a unit file
2847+
2848+
* **See also**
2849+
* https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html
2850+
2851+
Alias of
2852+
2853+
```puppet
2854+
Struct[{
2855+
Optional['What'] => String[1],
2856+
Optional['Where'] => Stdlib::Unixpath,
2857+
Optional['Type'] => String[1],
2858+
Optional['Options'] => String[1],
2859+
Optional['SloppyOptions'] => Boolean,
2860+
Optional['LazyUnmount'] => Boolean,
2861+
Optional['ReadWriteOnly'] => Boolean,
2862+
Optional['ForceUnmount'] => Boolean,
2863+
Optional['DirectoryMode'] => Stdlib::Filemode,
2864+
Optional['TimeoutSec'] => String[0],
2865+
}]
2866+
```
2867+
28012868
### <a name="Systemd--Unit--Path"></a>`Systemd::Unit::Path`
28022869

28032870
Possible keys for the [Path] section of a unit file

manifests/manage_dropin.pp

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
# @param timer_entry key value pairs for [Timer] section of the unit file
8989
# @param path_entry key value pairs for [Path] section of the unit file
9090
# @param socket_entry key value pairs for the [Socket] section of the unit file
91+
# @param mount_entry key value pairs for the [Mount] section of the unit file
9192
#
9293
define systemd::manage_dropin (
9394
Systemd::Unit $unit,
@@ -108,6 +109,7 @@
108109
Optional[Systemd::Unit::Timer] $timer_entry = undef,
109110
Optional[Systemd::Unit::Path] $path_entry = undef,
110111
Optional[Systemd::Unit::Socket] $socket_entry = undef,
112+
Optional[Systemd::Unit::Mount] $mount_entry = undef,
111113
) {
112114
if $timer_entry and $unit !~ Pattern['^[^/]+\.timer'] {
113115
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} timer_entry is only valid for timer units")
@@ -125,6 +127,10 @@
125127
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} slice_entry is only valid for slice units")
126128
}
127129

130+
if $mount_entry and $unit !~ Pattern['^[^/]+\.mount'] {
131+
fail("Systemd::Manage_dropin[${name}]: for unit ${unit} mount_entry is only valid for mount units")
132+
}
133+
128134
systemd::dropin_file { $name:
129135
ensure => $ensure,
130136
filename => $filename,
@@ -145,6 +151,7 @@
145151
'timer_entry' => $timer_entry,
146152
'path_entry' => $path_entry,
147153
'socket_entry' => $socket_entry,
154+
'mount_entry' => $mount_entry,
148155
}),
149156
}
150157
}

manifests/manage_unit.pp

+28
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,27 @@
6363
# },
6464
# }
6565
#
66+
# @example Mount a Filesystem and Use for a Service
67+
# systemd::manage_unit { 'var-lib-sss-db.mount':
68+
# ensure => present,
69+
# unit_entry => {
70+
# 'Description' => 'Mount sss tmpfs db',
71+
# },
72+
# mount_entry => {
73+
# 'What' => 'tmpfs',
74+
# 'Where' => '/var/lib/sss/db',
75+
# 'Type' => 'tmpfs',
76+
# 'Options' => 'size=300M,mode=0700,uid=sssd,gid=sssd,rootcontext=system_u:object_r:sssd_var_lib_t:s0',
77+
# },
78+
# }
79+
# systemd::manage_dropin { 'tmpfs-db.conf':
80+
# ensure => present,
81+
# unit => 'sssd.service',
82+
# unit_entry => {
83+
# 'RequiresMountsFor' => '/var/lib/sss/db',
84+
# },
85+
# }
86+
#
6687
# @example Remove a unit file
6788
# systemd::manage_unit { 'my.service':
6889
# ensure => 'absent',
@@ -96,6 +117,7 @@
96117
# @param timer_entry key value pairs for [Timer] section of the unit file
97118
# @param path_entry key value pairs for [Path] section of the unit file.
98119
# @param socket_entry kev value paors for [Socket] section of the unit file.
120+
# @param mount_entry kev value pairs for [Mount] section of the unit file.
99121
#
100122
define systemd::manage_unit (
101123
Enum['present', 'absent'] $ensure = 'present',
@@ -118,6 +140,7 @@
118140
Optional[Systemd::Unit::Timer] $timer_entry = undef,
119141
Optional[Systemd::Unit::Path] $path_entry = undef,
120142
Optional[Systemd::Unit::Socket] $socket_entry = undef,
143+
Optional[Systemd::Unit::Mount] $mount_entry = undef,
121144
) {
122145
assert_type(Systemd::Unit, $name)
123146

@@ -137,6 +160,10 @@
137160
fail("Systemd::Manage_unit[${name}]: slice_entry is only valid for slice units")
138161
}
139162

163+
if $mount_entry and $name !~ Pattern['^[^/]+\.mount'] {
164+
fail("Systemd::Manage_unit[${name}]: mount_entry is only valid for mount units")
165+
}
166+
140167
if $ensure != 'absent' and $name =~ Pattern['^[^/]+\.service'] and !$service_entry {
141168
fail("Systemd::Manage_unit[${name}]: service_entry is required for service units")
142169
}
@@ -162,6 +189,7 @@
162189
'timer_entry' => $timer_entry,
163190
'path_entry' => $path_entry,
164191
'socket_entry' => $socket_entry,
192+
'mount_entry' => $mount_entry,
165193
}),
166194
}
167195
}

spec/defines/manage_dropin_spec.rb

+19
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,25 @@
153153
}
154154
end
155155

156+
context 'on a mount' do
157+
let(:params) do
158+
{
159+
unit: 'var-lib-sss-db.mount',
160+
mount_entry: {
161+
'SloppyOptions' => true,
162+
}
163+
}
164+
end
165+
166+
it { is_expected.to compile.with_all_deps }
167+
168+
it {
169+
is_expected.to contain_systemd__dropin_file('foobar.conf').
170+
with_unit('var-lib-sss-db.mount').
171+
with_content(%r{^SloppyOptions=true$})
172+
}
173+
end
174+
156175
context 'on a slice' do
157176
let(:params) do
158177
{

spec/defines/manage_unit_spec.rb

+28
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,34 @@
9999
end
100100
end
101101

102+
context 'on a mount' do
103+
let(:title) { 'var-lib-sss-db.mount' }
104+
105+
let(:params) do
106+
{
107+
unit_entry: {
108+
Description: 'Mount sssd dir',
109+
},
110+
mount_entry: {
111+
'What' => 'tmpfs',
112+
'Where' => '/var/lib/sss/db',
113+
'Type' => 'tmpfs',
114+
'Options' => 'size=300M',
115+
},
116+
}
117+
end
118+
119+
it { is_expected.to compile.with_all_deps }
120+
121+
it {
122+
is_expected.to contain_systemd__unit_file('var-lib-sss-db.mount').
123+
with_content(%r{^\[Mount\]$}).
124+
with_content(%r{^What=tmpfs$}).
125+
with_content(%r{^Where=/var/lib/sss/db$}).
126+
with_content(%r{^Options=size=300M$})
127+
}
128+
end
129+
102130
context 'on a timer' do
103131
let(:title) { 'winter.timer' }
104132

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'Systemd::Unit::Mount' do
6+
context 'with a key of What can have thing to mount' do
7+
it { is_expected.to allow_value({ 'What' => 'tmpfs' }) }
8+
it { is_expected.to allow_value({ 'What' => 'nfs://example.org/exports/home' }) }
9+
it { is_expected.to allow_value({ 'What' => '/dev/vda1' }) }
10+
end
11+
12+
context 'with a key of Where can have a path to mount on' do
13+
it { is_expected.to allow_value({ 'Where' => '/mnt/foo' }) }
14+
it { is_expected.to allow_value({ 'Where' => '/mnt/foo/file.txt' }) }
15+
end
16+
17+
context 'with a key of Type can have a path to mount on' do
18+
it { is_expected.to allow_value({ 'Type' => 'tmpfs' }) }
19+
it { is_expected.to allow_value({ 'Type' => 'ext2' }) }
20+
end
21+
22+
context 'with a key of Options can have a path to mount on' do
23+
it { is_expected.to allow_value({ 'Options' => 'size=300M,mode=0700,uid=sssd,gid=sssd,root' }) }
24+
end
25+
26+
context 'with a key of DirectoryMode can have a mode of' do
27+
it { is_expected.to allow_value({ 'DirectoryMode' => '0700' }) }
28+
end
29+
30+
context 'with a key of TimeoutSec can have a mode of' do
31+
it { is_expected.to allow_value({ 'TimeoutSec' => '100' }) }
32+
it { is_expected.to allow_value({ 'TimeoutSec' => '5min 20s' }) }
33+
it { is_expected.to allow_value({ 'TimeoutSec' => '' }) }
34+
end
35+
36+
%w[SloppyOptions LazyUnmount ReadWriteOnly ForceUnmount].each do |assert|
37+
context "with a key of #{assert} can have values of a path" do
38+
it { is_expected.to allow_value({ assert => false }) }
39+
it { is_expected.to allow_value({ assert => true }) }
40+
end
41+
end
42+
end

templates/unit_file.epp

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
Optional[Hash] $timer_entry,
77
Optional[Hash] $path_entry,
88
Optional[Hash] $socket_entry,
9+
Optional[Hash] $mount_entry,
910
| -%>
1011
<%-
1112

@@ -20,6 +21,7 @@
2021
'Path',
2122
'Socket',
2223
'Install',
24+
'Mount',
2325
]
2426

2527
# Directives which are pair of items to be expressed as a space seperated pair.

types/unit/mount.pp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# @summary Possible keys for the [Mount] section of a unit file
2+
# @see https://www.freedesktop.org/software/systemd/man/latest/systemd.mount.html
3+
#
4+
type Systemd::Unit::Mount = Struct[
5+
{
6+
Optional['What'] => String[1],
7+
Optional['Where'] => Stdlib::Unixpath,
8+
Optional['Type'] => String[1],
9+
Optional['Options'] => String[1],
10+
Optional['SloppyOptions'] => Boolean,
11+
Optional['LazyUnmount'] => Boolean,
12+
Optional['ReadWriteOnly'] => Boolean,
13+
Optional['ForceUnmount'] => Boolean,
14+
Optional['DirectoryMode'] => Stdlib::Filemode,
15+
Optional['TimeoutSec'] => String[0],
16+
}
17+
]

0 commit comments

Comments
 (0)