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