6e9988cc5f48c7874a096ef9bc4a5cb84b844c39
[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       tag     => $bacula::tag_bacula_dsa_client_list,
62       target  => $bacula::bacula_dsa_client_list,
63       content => $client,
64     }
65
66     # allow access from director
67     Ferm::Rule::Simple <<| tag == "bacula::director-to-fd::${director_server}" |>> {
68       port => $port_fd,
69     }
70
71     # get access to the storage
72     @@ferm::rule::simple { "bacula::fd-to-storage::${client}":
73       tag         => "bacula::fd-to-storage::${storage_server}",
74       description => 'Allow bacula-fd access to the bacula-storage',
75       chain       => 'bacula-sd',
76       saddr       => $bacula::public_addresses,
77     }
78   } elsif $ensure == 'absent' {
79     file { '/etc/bacula':
80       ensure  => absent,
81       purge   => true,
82       force   => true,
83       recurse => true;
84     }
85   }
86
87   ensure_packages ( [
88     'bacula-fd',
89     'bacula-common',
90   ], {
91     ensure => $package_ensure
92   })
93
94   service { 'bacula-fd':
95     ensure    => $service_ensure,
96     enable    => $service_enable,
97     hasstatus => true,
98   }
99   dsa_systemd::override { 'bacula-fd':
100     ensure  => $ensure,
101     content => @(EOF),
102       [Unit]
103       After=unbound.service
104       [Service]
105       ExecStart=
106       ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
107       | EOF
108   }
109
110   exec { 'bacula-fd restart-when-idle':
111     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
112     command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${port_fd} bacula-fd &'",
113     refreshonly => true,
114     subscribe   => [ File[$bacula::bacula_ssl_server_cert], File[$bacula::bacula_ssl_client_cert] ],
115     require     => [ File['/usr/local/sbin/bacula-idle-restart'], File['/etc/bacula/fd-conf.d/empty.conf'] ],
116   }
117
118   file { '/etc/bacula/bacula-fd.conf':
119     ensure  => $ensure,
120     content => template('bacula/bacula-fd.conf.erb'),
121     mode    => '0640',
122     owner   => root,
123     group   => bacula,
124     notify  => Exec['bacula-fd restart-when-idle'],
125   }
126   file { '/etc/bacula/fd-conf.d/empty.conf':
127     ensure  => $ensure,
128     content => '',
129     mode    => '0440',
130     group   => bacula,
131     notify  => Exec['bacula-fd restart-when-idle'],
132   }
133   file { '/usr/local/sbin/bacula-backup-dirs':
134     ensure => $ensure,
135     mode   => '0775',
136     source => 'puppet:///modules/bacula/bacula-backup-dirs',
137   }
138   file { '/usr/local/sbin/postbaculajob':
139     ensure => $ensure,
140     mode   => '0775',
141     source => 'puppet:///modules/bacula/postbaculajob',
142   }
143   file { '/etc/default/bacula-fd':
144     ensure  => $ensure,
145     content => template('bacula/default.bacula-fd.erb'),
146     mode    => '0400',
147     owner   => root,
148     group   => root,
149     notify  => Service['bacula-fd'],
150   }
151 }