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