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