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