83d0253079e0d5fa282db8faa9a67eac6abd4114
[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 # @param volume_retention_full  how long to keep volumes with full backups
12 # @param volume_retention_diff  how long to keep volumes with differential backups
13 # @param volume_retention_inc   how long to keep volumes with incremental backups
14 # @param file_retention         how long to keep information about which files are in which volumes/jobs
15 # @param job_retention          how long to keep job records
16 class bacula::client(
17   Stdlib::Host $director_server,
18   Stdlib::Host $storage_server,
19   Integer $port_fd = 9102,
20   String $client_name = "${::fqdn}-fd",
21   Enum['present', 'absent'] $ensure = defined(Class['bacula::not_a_client']) ? { true => 'absent', default => 'present' },
22   String $volume_retention_full = '100 days',
23   String $volume_retention_diff = '50 days',
24   String $volume_retention_inc  = '30 days',
25   String $file_retention = '30 days',
26   String $job_retention = $volume_retention_full,
27 ) inherits bacula {
28   $package_ensure = $ensure ? { 'present' => 'installed', 'absent' => 'purged' }
29   $service_ensure = $ensure ? { 'present' => 'running', 'absent'  => 'stopped' }
30   $service_enable = $ensure ? { 'present' => true, 'absent' => false }
31   $reverse_ensure = $ensure ? { 'present' => 'absent', 'absent' => 'present' }
32   $directory_ensure = $ensure ? { 'present' => 'directory', 'absent' => 'absent' }
33
34   $client = $::fqdn
35
36   file { '/etc/bacula/fd-conf.d':
37     ensure  => $directory_ensure,
38     mode    => '0755',
39     group   => bacula,
40     purge   => true,
41     force   => true,
42     recurse => true,
43     notify  => Exec['bacula-fd restart-when-idle'],
44   }
45
46   if $ensure == 'present' {
47     Bacula::Client::Director <<| tag == "bacula::to-fd::${director_server}" |>> {
48       before => Exec['bacula-fd restart-when-idle'],
49     }
50
51     @@bacula::storage::client { $client:
52       tag                   => "bacula::to-storage::${storage_server}",
53       client                => $client,
54       director_server       => $director_server,
55       volume_retention_full => $volume_retention_full,
56       volume_retention_diff => $volume_retention_diff,
57       volume_retention_inc  => $volume_retention_inc,
58     }
59
60     @@concat::fragment { "bacula-dsa-client-list::${client}":
61       target  => $bacula::bacula_dsa_client_list ,
62       content => @("EOF"),
63           ${client}
64           | EOF
65       tag     => $bacula::tag_bacula_dsa_client_list,
66     }
67
68     # allow access from director
69     Ferm::Rule::Simple <<| tag == "bacula::director-to-fd::${director_server}" |>> {
70       port => $port_fd,
71     }
72
73     # get access to the storage
74     @@ferm::rule::simple { "bacula::fd-to-storage::${client}":
75       tag         => "bacula::fd-to-storage::${storage_server}",
76       description => 'Allow bacula-fd access to the bacula-storage',
77       chain       => 'bacula-sd',
78       saddr       => $bacula::public_addresses,
79     }
80   } elsif $ensure == 'absent' {
81     file { '/etc/bacula':
82       ensure  => absent,
83       purge   => true,
84       force   => true,
85       recurse => true;
86     }
87   }
88
89   ensure_packages ( [
90     'bacula-fd',
91     'bacula-common',
92   ], {
93     ensure => $package_ensure
94   })
95
96   service { 'bacula-fd':
97     ensure    => $service_ensure,
98     enable    => $service_enable,
99     hasstatus => true,
100   }
101   dsa_systemd::override { 'bacula-fd':
102     ensure  => $ensure,
103     content => @(EOF),
104       [Unit]
105       After=unbound.service
106       [Service]
107       ExecStart=
108       ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
109       | EOF
110   }
111
112   exec { 'bacula-fd restart-when-idle':
113     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
114     command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${port_fd} bacula-fd &'",
115     refreshonly => true,
116     subscribe   => [ File[$bacula::bacula_ssl_server_cert], File[$bacula::bacula_ssl_client_cert] ],
117     require     => [ File['/usr/local/sbin/bacula-idle-restart'], File['/etc/bacula/fd-conf.d/empty.conf'] ],
118   }
119
120   file { '/etc/bacula/bacula-fd.conf':
121     ensure  => $ensure,
122     content => template('bacula/bacula-fd.conf.erb'),
123     mode    => '0640',
124     owner   => root,
125     group   => bacula,
126     notify  => Exec['bacula-fd restart-when-idle'],
127   }
128   file { '/etc/bacula/fd-conf.d/empty.conf':
129     ensure  => $ensure,
130     content => '',
131     mode    => '0440',
132     group   => bacula,
133     notify  => Exec['bacula-fd restart-when-idle'],
134   }
135   file { '/usr/local/sbin/bacula-backup-dirs':
136     ensure => $ensure,
137     mode   => '0775',
138     source => 'puppet:///modules/bacula/bacula-backup-dirs',
139   }
140   file { '/usr/local/sbin/postbaculajob':
141     ensure => $ensure,
142     mode   => '0775',
143     source => 'puppet:///modules/bacula/postbaculajob',
144   }
145   file { '/etc/default/bacula-fd':
146     ensure  => $ensure,
147     content => template('bacula/default.bacula-fd.erb'),
148     mode    => '0400',
149     owner   => root,
150     group   => root,
151     notify  => Service['bacula-fd'],
152   }
153 }