fix a variable name
[mirror/dsa-puppet.git] / modules / dsa_systemd / manifests / socket_service.pp
1 # define and enable (or disable) a .socket activated .service
2 #
3 define dsa_systemd::socket_service(
4   Enum['present','absent'] $ensure = 'present',
5   String $service_content,
6   String $socket_content,
7 ) {
8   $ensure_service = $ensure ? {
9     present => running,
10     absent  => stopped,
11   }
12
13   $ensure_enable = $ensure ? {
14     present => true,
15     absent  => false,
16   }
17
18   $systemd_service = "${name}.socket"
19   $service_file = "/etc/systemd/system/${name}@.service"
20   $socket_file = "/etc/systemd/system/${systemd_service}"
21
22   # if we enable the service, we want the files before the service, so we
23   #   subscribe the service to the files.
24   # if we remove the service, we want the service disabled before the files
25   #   go away, so we say the service needs the files to be handled before.
26   $service_before = $ensure ? {
27     present => [],
28     default => [
29       File[$service_file],
30       File[$socket_file],
31     ],
32   }
33   $service_subscribe = $ensure ? {
34     present => [
35       File[$service_file],
36       File[$socket_file],
37     ],
38     default => [],
39   }
40
41
42   file { $service_file:
43     ensure  => $ensure,
44     content => $service_content,
45     notify  => Exec['systemctl daemon-reload'],
46   }
47
48   file { $socket_file:
49     ensure  => $ensure,
50     content => $socket_content,
51     notify  => Exec['systemctl daemon-reload'],
52   }
53
54   service { $systemd_service:
55     ensure    => $ensure_service,
56     enable    => $ensure_enable,
57     notify    => Exec['systemctl daemon-reload'],
58     provider  => systemd,
59     before    => $service_before,
60     subscribe => $service_subscribe,
61   }
62 }