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