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