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