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