1 # service instance for Debian's mirror-health checker
3 # for each defined service, a daemon will regularly check if the
4 # local version of <url> matches the majority version among the
5 # set of all hosts that define a <service_name>.
7 # the result of this check is then exposed via <health_url>
9 # @param url URL to check for freshness on each host (normally a Release file)
10 # @param health_url URL to the health marker
11 # @param this_host_service_name this host's service name for this service.
12 # Other nodes will connect to this hostname to
13 # fetch url for checking.
14 # If this is undef, other hosts will not
16 # @param check_service name of this service
17 # @param check_interval how often to check
18 # @param ensure present or absent
19 define mirror_health::service (
22 Optional[String] $this_host_service_name = undef,
23 String $check_service = $name,
24 Integer $check_interval = 60,
25 Enum['present','absent'] $ensure = 'present',
29 $service_file = "/etc/systemd/system/mirror-health-${check_service}.service"
32 # if we enable the service, we want the files before the service, so we
33 # subscribe the service to the files.
34 # if we remove the service, we want the service disabled before the files
35 # go away, so we say the service needs the files to be handled before.
36 $service_before = $ensure ? {
38 default => [ File[$service_file], ],
40 $service_subscribe = $ensure ? {
41 present => [ File[$service_file], ],
44 $ensure_service = $ensure ? {
48 $ensure_enable = $ensure ? {
55 content => template('mirror_health/mirror-health.service.erb'),
56 notify => Exec['systemctl daemon-reload'],
58 service { "mirror-health-${check_service}":
59 ensure => $ensure_service,
60 enable => $ensure_enable,
61 notify => Exec['systemctl daemon-reload'],
62 before => $service_before,
63 subscribe => $service_subscribe + [ File[ $mirror_health::script ] ],
67 $hosts_file = "${mirror_health::confdir}/${check_service}.hosts"
68 $tag = "mirror_health::service::${check_service}::hosts"
71 ensure_newline => true,
73 notify => Service["mirror-health-${check_service}"],
75 if $this_host_service_name and $ensure == 'present' {
76 @@concat::fragment { "mirror_health::service::${check_service}::hosts::${this_host_service_name}":
78 target => $hosts_file,
79 content => $this_host_service_name,
82 Concat::Fragment <<| tag == $tag |>>