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