-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathsocket_service.pp
69 lines (63 loc) · 2.28 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# @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
# @param ensure
# State of the socket service to ensure. Present means it ensures it's
# present, but doesn't ensure the service state.
# @param socket_content
# The content for the socket unit file. Required if ensure isn't absent.
# @param service_content
# The content for the service unit file. Required if ensure isn't absent.
# @param enable
# Whether to enable or disable the service. By default this is derived from
# $ensure but can be overridden for advanced use cases where the service is
# running during a migration but shouldn't be enabled on boot.
define systemd::socket_service (
Enum['running', 'stopped', 'present', 'absent'] $ensure = 'running',
Optional[String[1]] $socket_content = undef,
Optional[String[1]] $service_content = undef,
Optional[Boolean] $enable = 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,
}
# https://tickets.puppetlabs.com/browse/MODULES-11018
if $enable == undef and $active == undef {
$real_enable = undef
} else {
$real_enable = pick($enable, $active)
}
$unit_file_ensure = bool2str($ensure == 'absent', 'absent', 'present')
systemd::unit_file { "${name}.socket":
ensure => $unit_file_ensure,
content => $socket_content,
active => $active,
enable => $real_enable,
}
systemd::unit_file { "${name}.service":
ensure => $unit_file_ensure,
content => $service_content,
active => $active,
enable => $real_enable,
}
if $active != undef or $real_enable != undef {
# Systemd needs both .socket and .service to be loaded when starting the
# service. The unit_file takes care of matching, this ensures the
# non-matching order.
File["/etc/systemd/system/${name}.socket"] -> Service["${name}.service"]
File["/etc/systemd/system/${name}.service"] -> Service["${name}.socket"]
}
}