Only restart once we have at least one file in the .d dir
[mirror/dsa-puppet.git] / modules / bacula / manifests / client.pp
1 # our bacula client configuration
2 #
3 # this mostly configures the file daemon, but also firewall rules and
4 # fragments to sent to the other servers.
5 #
6 # @param director_server  director server (address) that controls this client's backups
7 # @param storage_server   storage server (address) to use for this client
8 # @param port_fd          port that bacula-fd listens on
9 # @param client_name      bacula client name for this instance
10 # @param ensure           present or absent
11 class bacula::client(
12   Stdlib::Host $director_server,
13   Stdlib::Host $storage_server,
14   Integer $port_fd = 9102,
15   String $client_name = "${::fqdn}-fd",
16   Enum['present', 'absent'] $ensure = defined(Class['bacula::not_a_client']) ? { true => 'absent', default => 'present' },
17 ) inherits bacula {
18   $package_ensure = $ensure ? { 'present' => 'installed', 'absent' => 'purged' }
19   $service_ensure = $ensure ? { 'present' => 'running', 'absent'  => 'stopped' }
20   $service_enable = $ensure ? { 'present' => true, 'absent' => false }
21   $reverse_ensure = $ensure ? { 'present' => 'absent', 'absent' => 'present' }
22   $directory_ensure = $ensure ? { 'present' => 'directory', 'absent' => 'absent' }
23
24   $client = $::fqdn
25
26   file { '/etc/bacula/fd-conf.d':
27     ensure  => $directory_ensure,
28     mode    => '0755',
29     group   => bacula,
30     purge   => true,
31     force   => true,
32     recurse => true,
33     notify  => Exec['bacula-fd restart-when-idle'],
34   }
35
36   if $ensure == 'present' {
37     Bacula::Client::Director <<| tag == "bacula::to-fd::${director_server}" |>>
38
39     @@bacula::storage::client { $client:
40       tag             => "bacula::to-storage::${storage_server}",
41       client          => $client,
42       director_server => $director_server,
43     }
44
45     @@concat::fragment { "bacula-dsa-client-list::${client}":
46       target  => $bacula::bacula_dsa_client_list ,
47       content => @("EOF"),
48           ${client}
49           | EOF
50       tag     => $bacula::tag_bacula_dsa_client_list,
51     }
52
53     # allow access from director
54     Ferm::Rule::Simple <<| tag == "bacula::director-to-fd::${director_server}" |>> {
55       port => $port_fd,
56     }
57
58     # get access to the storage
59     @@ferm::rule::simple { "bacula::fd-to-storage::${client}":
60       tag         => "bacula::fd-to-storage::${storage_server}",
61       description => 'Allow bacula-fd access to the bacula-storage',
62       chain       => 'bacula-sd',
63       saddr       => $bacula::public_addresses,
64     }
65   } elsif $ensure == 'absent' {
66     file { '/etc/bacula':
67       ensure  => absent,
68       purge   => true,
69       force   => true,
70       recurse => true;
71     }
72   }
73
74   ensure_packages ( [
75     'bacula-fd',
76     'bacula-common',
77   ], {
78     ensure => $package_ensure
79   })
80
81   service { 'bacula-fd':
82     ensure    => $service_ensure,
83     enable    => $service_enable,
84     hasstatus => true,
85   }
86
87   exec { 'bacula-fd restart-when-idle':
88     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
89     command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${port_fd} bacula-fd &'",
90     refreshonly => true,
91     subscribe   => [ File[$bacula::bacula_ssl_server_cert], File[$bacula::bacula_ssl_client_cert] ],
92     require     => [ File['/usr/local/sbin/bacula-idle-restart'], File['/etc/bacula/fd-conf.d/empty.conf'] ],
93   }
94
95   file { '/etc/bacula/bacula-fd.conf':
96     ensure  => $ensure,
97     content => template('bacula/bacula-fd.conf.erb'),
98     mode    => '0640',
99     owner   => root,
100     group   => bacula,
101     notify  => Exec['bacula-fd restart-when-idle'],
102   }
103   file { '/etc/bacula/fd-conf.d/empty.conf':
104     ensure  => $ensure,
105     content => '',
106     mode    => '0440',
107     group   => bacula,
108     notify  => Exec['bacula-fd restart-when-idle'],
109   }
110   file { '/usr/local/sbin/bacula-backup-dirs':
111     ensure => $ensure,
112     mode   => '0775',
113     source => 'puppet:///modules/bacula/bacula-backup-dirs',
114   }
115   file { '/usr/local/sbin/postbaculajob':
116     ensure => $ensure,
117     mode   => '0775',
118     source => 'puppet:///modules/bacula/postbaculajob',
119   }
120   file { '/etc/default/bacula-fd':
121     ensure  => $ensure,
122     content => template('bacula/default.bacula-fd.erb'),
123     mode    => '0400',
124     owner   => root,
125     group   => root,
126     notify  => Service['bacula-fd'],
127   }
128   if (versioncmp($::lsbmajdistrelease, '9') >= 0 and $facts['systemd']) {
129     dsa_systemd::override { 'bacula-fd':
130       content => @(EOT)
131         [Service]
132         ExecStart=
133         ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
134         | EOT
135     }
136   } else {
137     dsa_systemd::override { 'bacula-fd':
138       ensure  => absent,
139     }
140   }
141 }