e302f80c5c5f1b97991d180740268bea4c6f1cf0
[mirror/dsa-puppet.git] / modules / mirror_health / manifests / service.pp
1 # base class for Debian's mirror-health checker
2 define mirror_health::service (
3   String $url,
4   String $health_url,
5   String $this_host_service_name = $::fqdn,
6   String $check_service = $name,
7   Integer $check_interval = 60,
8   Enum['present','absent'] $ensure = 'present',
9 ) {
10   include mirror_health
11
12   $service_file = "/etc/systemd/system/mirror-health-${check_service}.service"
13
14   file { $service_file:
15     content => template('mirror_health/mirror-health.service.erb'),
16     notify  => [Exec['systemctl daemon-reload'], Service["mirror-health-${check_service}"]],
17   }
18
19   $service_before = $ensure ? {
20     present => [],
21     default => [ File[$service_file], ],
22   }
23   $service_subscribe = $ensure ? {
24     present => [ File[$service_file], ],
25     default => [],
26   }
27
28   $ensure_service = $ensure ? {
29     present => running,
30     absent  => stopped,
31   }
32   $ensure_enable = $ensure ? {
33     present => true,
34     absent  => false,
35   }
36   service { "mirror-health-${check_service}":
37     ensure    => $ensure_service,
38     enable    => $ensure_enable,
39     require   => Exec['systemctl daemon-reload'],
40     before    => $service_before,
41     subscribe => $service_subscribe + [ File[ $mirror_health::script ] ],
42   }
43
44   $hosts_file = "${mirror_health::confdir}/${check_service}.hosts"
45   $tag = "mirror_health::service::${check_service}::hosts"
46   concat { $hosts_file:
47     ensure         => $ensure,
48     ensure_newline => true,
49     mode           => '0444',
50     notify         => Service["mirror-health-${check_service}"],
51   }
52   @@concat::fragment { "mirror_health::service::${check_service}::hosts::${this_host_service_name}":
53     tag     => $tag,
54     target  => $hosts_file,
55     content => $this_host_service_name,
56   }
57   Concat::Fragment <<| tag == $tag |>>
58 }