-
-
Notifications
You must be signed in to change notification settings - Fork 148
/
Copy pathsocket_service.pp
47 lines (41 loc) · 1.22 KB
/
socket_service.pp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# @summary Create a systemd socket activated service
# @api public
#
# Systemd socket activated services have their own dependencies. This is a
# convenience wrapper around systemd::unit_file.
#
# @param name [Pattern['^[^/]+$']]
# The target unit file to create
define systemd::socket_service (
Enum['running', 'stopped', 'present', 'absent'] $ensure = 'running',
Optional[String[1]] $socket_content = undef,
Optional[String[1]] $service_content = undef,
) {
assert_type(Pattern['^[^/]+$'], $name)
if $ensure != 'absent' {
assert_type(NotUndef, $socket_content)
assert_type(NotUndef, $service_content)
}
$active = $ensure ? {
'running' => true,
'stopped' => false,
'absent' => false,
default => undef,
}
$unit_file_ensure = bool2str($ensure == 'absent', 'absent', 'present')
systemd::unit_file { "${name}.socket":
ensure => $unit_file_ensure,
content => $socket_content,
active => $active,
enable => $active,
}
systemd::unit_file { "${name}.service":
ensure => $unit_file_ensure,
content => $service_content,
active => $active,
enable => $active,
}
if $active {
File["/etc/systemd/system/${name}.socket"] -> Service["${name}.service"]
}
}