All our systems are now at least Debian 9
[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   $directory_ensure = $ensure ? { 'present' => 'directory', 'absent' => 'absent' }
23
24   $client = $::fqdn
25
26   file { '/etc/bacula/fd-conf.d':
27     ensure  => $directory_ensure,
28     mode    => '0755',
29     group   => bacula,
30     purge   => true,
31     force   => true,
32     recurse => true,
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       before => Exec['bacula-fd restart-when-idle'],
39     }
40
41     @@bacula::storage::client { $client:
42       tag             => "bacula::to-storage::${storage_server}",
43       client          => $client,
44       director_server => $director_server,
45     }
46
47     @@concat::fragment { "bacula-dsa-client-list::${client}":
48       target  => $bacula::bacula_dsa_client_list ,
49       content => @("EOF"),
50           ${client}
51           | EOF
52       tag     => $bacula::tag_bacula_dsa_client_list,
53     }
54
55     # allow access from director
56     Ferm::Rule::Simple <<| tag == "bacula::director-to-fd::${director_server}" |>> {
57       port => $port_fd,
58     }
59
60     # get access to the storage
61     @@ferm::rule::simple { "bacula::fd-to-storage::${client}":
62       tag         => "bacula::fd-to-storage::${storage_server}",
63       description => 'Allow bacula-fd access to the bacula-storage',
64       chain       => 'bacula-sd',
65       saddr       => $bacula::public_addresses,
66     }
67   } elsif $ensure == 'absent' {
68     file { '/etc/bacula':
69       ensure  => absent,
70       purge   => true,
71       force   => true,
72       recurse => true;
73     }
74   }
75
76   ensure_packages ( [
77     'bacula-fd',
78     'bacula-common',
79   ], {
80     ensure => $package_ensure
81   })
82
83   service { 'bacula-fd':
84     ensure    => $service_ensure,
85     enable    => $service_enable,
86     hasstatus => true,
87   }
88   dsa_systemd::override { 'bacula-fd':
89     ensure  => $ensure,
90     content => @(EOF),
91       [Unit]
92       After=network-online.target
93       [Service]
94       ExecStart=
95       ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
96       | EOF
97   }
98
99   exec { 'bacula-fd restart-when-idle':
100     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
101     command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${port_fd} bacula-fd &'",
102     refreshonly => true,
103     subscribe   => [ File[$bacula::bacula_ssl_server_cert], File[$bacula::bacula_ssl_client_cert] ],
104     require     => [ File['/usr/local/sbin/bacula-idle-restart'], File['/etc/bacula/fd-conf.d/empty.conf'] ],
105   }
106
107   file { '/etc/bacula/bacula-fd.conf':
108     ensure  => $ensure,
109     content => template('bacula/bacula-fd.conf.erb'),
110     mode    => '0640',
111     owner   => root,
112     group   => bacula,
113     notify  => Exec['bacula-fd restart-when-idle'],
114   }
115   file { '/etc/bacula/fd-conf.d/empty.conf':
116     ensure  => $ensure,
117     content => '',
118     mode    => '0440',
119     group   => bacula,
120     notify  => Exec['bacula-fd restart-when-idle'],
121   }
122   file { '/usr/local/sbin/bacula-backup-dirs':
123     ensure => $ensure,
124     mode   => '0775',
125     source => 'puppet:///modules/bacula/bacula-backup-dirs',
126   }
127   file { '/usr/local/sbin/postbaculajob':
128     ensure => $ensure,
129     mode   => '0775',
130     source => 'puppet:///modules/bacula/postbaculajob',
131   }
132   file { '/etc/default/bacula-fd':
133     ensure  => $ensure,
134     content => template('bacula/default.bacula-fd.erb'),
135     mode    => '0400',
136     owner   => root,
137     group   => root,
138     notify  => Service['bacula-fd'],
139   }
140 }