do bacula backups iff we do not include the bacula::not_a_client class
[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 class bacula::client(
6   Enum['present', 'absent'] $ensure = defined(Class["bacula::not_a_client"]) ? { true => 'absent', default => 'present' },
7 ) inherits bacula {
8   $package_ensure = $ensure ? { 'present' => 'installed', 'absent' => 'purged' }
9   $service_ensure = $ensure ? { 'present' => 'running', 'absent'  => 'stopped' }
10   $service_enable = $ensure ? { 'present' => true, 'absent' => false }
11   $reverse_ensure = $ensure ? { 'present' => 'absent', 'absent' => 'present' }
12
13   if $ensure == 'present' {
14     @@bacula::storage_per_node { $::fqdn: }
15
16     @@bacula::node { $::fqdn:
17       bacula_client_port => $bacula::bacula_client_port,
18     }
19
20     @@concat::fragment { "bacula-dsa-client-list::$fqdn":
21       target  => $bacula::bacula_dsa_client_list ,
22       content => @("EOF"),
23           ${fqdn}
24           | EOF
25       tag     => $bacula::tag_bacula_dsa_client_list,
26     }
27   } elsif $ensure == 'absent' {
28     file { '/etc/bacula':
29       ensure  => absent,
30       purge   => true,
31       force   => true,
32       recurse => true;
33     }
34   }
35
36   package { ['bacula-fd', 'bacula-common']:
37     ensure => $package_ensure
38   }
39
40   service { 'bacula-fd':
41     ensure    => $service_ensure,
42     enable    => $service_enable,
43     hasstatus => true,
44     require   => Package['bacula-fd']
45   }
46
47   exec { 'bacula-fd restart-when-idle':
48     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
49     command     => 'sh -c "setsid /usr/local/sbin/bacula-idle-restart fd &"',
50     refreshonly => true,
51     subscribe   => [ File[$bacula_ssl_server_cert], File[$bacula_ssl_client_cert] ],
52     require     => File['/usr/local/sbin/bacula-idle-restart'],
53   }
54
55   file { '/etc/bacula/bacula-fd.conf':
56     ensure  => $ensure,
57     content => template('bacula/bacula-fd.conf.erb'),
58     mode    => '0640',
59     owner   => root,
60     group   => bacula,
61     require => Package['bacula-fd'],
62     notify  => Exec['bacula-fd restart-when-idle'],
63   }
64   file { '/usr/local/sbin/bacula-backup-dirs':
65     ensure  => $ensure,
66     mode    => '0775',
67     source  => 'puppet:///modules/bacula/bacula-backup-dirs',
68   }
69   file { '/usr/local/sbin/postbaculajob':
70     ensure  => $ensure,
71     mode    => '0775',
72     source  => 'puppet:///modules/bacula/postbaculajob',
73   }
74   file { '/etc/default/bacula-fd':
75     ensure  => $ensure,
76     content => template('bacula/default.bacula-fd.erb'),
77     mode    => '0400',
78     owner   => root,
79     group   => root,
80     require => Package['bacula-fd'],
81     notify  => Service['bacula-fd'],
82   }
83   if (versioncmp($::lsbmajdistrelease, '9') >= 0 and $systemd) {
84     dsa_systemd::override { 'bacula-fd':
85       content => @(EOT)
86         [Service]
87         ExecStart=
88         ExecStart=/usr/sbin/bacula-fd -c $CONFIG -f -u bacula -k
89         | EOT
90     }
91   } else {
92     dsa_systemd::override { 'bacula-fd':
93       ensure  => absent,
94     }
95   }
96
97   ferm::rule { 'dsa-bacula-fd':
98     domain      => '(ip ip6)',
99     description => 'Allow bacula access from storage and director',
100     rule        => "proto tcp mod state state (NEW) dport (${bacula_client_port}) saddr (${bacula_director_ip_addrs}) ACCEPT",
101   }
102 }