limit -sd access to bacula clients and the director
[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 class bacula::client(
6   Enum['present', 'absent'] $ensure = defined(Class['bacula::not_a_client']) ? { true => 'absent', default => 'present' },
7 ) inherits bacula {
8   $package_ensure = $ensure ? { 'present' => 'installed', 'absent' => 'purged' }
9   $service_ensure = $ensure ? { 'present' => 'running', 'absent'  => 'stopped' }
10   $service_enable = $ensure ? { 'present' => true, 'absent' => false }
11   $reverse_ensure = $ensure ? { 'present' => 'absent', 'absent' => 'present' }
12
13   if $ensure == 'present' {
14     @@bacula::storage_per_node { $::fqdn: }
15
16     @@bacula::node { $::fqdn:
17       bacula_client_port => $bacula::bacula_client_port,
18     }
19
20     @@concat::fragment { "bacula-dsa-client-list::${::fqdn}":
21       target  => $bacula::bacula_dsa_client_list ,
22       content => @("EOF"),
23           ${::fqdn}
24           | EOF
25       tag     => $bacula::tag_bacula_dsa_client_list,
26     }
27
28     # allow access from director
29     Ferm::Rule::Simple <<| tag == "bacula::director-to-fd::${bacula::bacula_director_address}" |>> {
30       port => $bacula::bacula_client_port,
31     }
32
33     # get access to the storage
34     @@ferm::rule::simple { "bacula::fd-to-storage::${::fqdn}":
35       tag         => "bacula::director-to-storage::${bacula::bacula_storage_address}",
36       description => 'Allow bacula-fd access to the bacula-storage',
37       chain       => 'bacula-sd',
38       saddr       => $bacula::public_addresses,
39     }
40   } elsif $ensure == 'absent' {
41     file { '/etc/bacula':
42       ensure  => absent,
43       purge   => true,
44       force   => true,
45       recurse => true;
46     }
47   }
48
49   ensure_packages ( [
50     'bacula-fd',
51     'bacula-common',
52   ], {
53     ensure => $package_ensure
54   })
55
56   service { 'bacula-fd':
57     ensure    => $service_ensure,
58     enable    => $service_enable,
59     hasstatus => true,
60     require   => Package['bacula-fd']
61   }
62
63   exec { 'bacula-fd restart-when-idle':
64     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
65     command     => 'sh -c "setsid /usr/local/sbin/bacula-idle-restart fd &"',
66     refreshonly => true,
67     subscribe   => [ File[$bacula::bacula_ssl_server_cert], File[$bacula::bacula_ssl_client_cert] ],
68     require     => File['/usr/local/sbin/bacula-idle-restart'],
69   }
70
71   file { '/etc/bacula/bacula-fd.conf':
72     ensure  => $ensure,
73     content => template('bacula/bacula-fd.conf.erb'),
74     mode    => '0640',
75     owner   => root,
76     group   => bacula,
77     require => Package['bacula-fd'],
78     notify  => Exec['bacula-fd restart-when-idle'],
79   }
80   file { '/usr/local/sbin/bacula-backup-dirs':
81     ensure => $ensure,
82     mode   => '0775',
83     source => 'puppet:///modules/bacula/bacula-backup-dirs',
84   }
85   file { '/usr/local/sbin/postbaculajob':
86     ensure => $ensure,
87     mode   => '0775',
88     source => 'puppet:///modules/bacula/postbaculajob',
89   }
90   file { '/etc/default/bacula-fd':
91     ensure  => $ensure,
92     content => template('bacula/default.bacula-fd.erb'),
93     mode    => '0400',
94     owner   => root,
95     group   => root,
96     require => Package['bacula-fd'],
97     notify  => Service['bacula-fd'],
98   }
99   if (versioncmp($::lsbmajdistrelease, '9') >= 0 and $facts['systemd']) {
100     dsa_systemd::override { 'bacula-fd':
101       content => @(EOT)
102         [Service]
103         ExecStart=
104         ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
105         | EOT
106     }
107   } else {
108     dsa_systemd::override { 'bacula-fd':
109       ensure  => absent,
110     }
111   }
112 }