continue with moving director name/address to a more local thing
[mirror/dsa-puppet.git] / modules / bacula / manifests / storage.pp
1 # the bacula storage node
2 #
3 # @param backup_path      directory where backups should be stored
4 # @param filestor_device  storage device name prefix
5 # @param filestor_name    storage device media type name prefix
6 # @param port_sd          port for the sd to listen on
7 # @param storage_name     bacula name of this sd instance
8 # @param storage_address  address of this sd instance that other instances should connect to (dns name)
9 # @param has_ipv4         SD should listen on ipv4
10 # @param has_ipv6         SD should listen on ipv6
11 class bacula::storage (
12   String $backup_path     = '/srv/bacula',
13   String $filestor_device = 'FileStorage',
14   String $filestor_name   = 'File',
15   Integer $port_sd        = 9103,
16   String $storage_name    = "${::fqdn}-sd",
17   Stdlib::Host $storage_address = $::fqdn,
18   Boolean $has_ipv4        = $bacula::public_addresses.any |$addr| { $addr =~ Stdlib::IP::Address::V4 },
19   Boolean $has_ipv6        = $bacula::public_addresses.any |$addr| { $addr =~ Stdlib::IP::Address::V6 },
20 ) inherits bacula {
21   $storage_secret = hkdf('/etc/puppet/secret', "bacula-sd-${::fqdn}")
22
23   package { 'bacula-sd':
24     ensure => installed
25   }
26
27   service { 'bacula-sd':
28     ensure    => running,
29     enable    => true,
30     hasstatus => true,
31   }
32   dsa_systemd::override { 'bacula-sd':
33     content => @(EOT)
34       [Service]
35       Group=bacula
36       SupplementaryGroups=ssl-cert
37       | EOT
38   }
39
40   exec { 'bacula-sd restart-when-idle':
41     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
42     command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${port_sd} bacula-sd &'",
43     refreshonly => true,
44     subscribe   => File[$bacula::bacula_ssl_server_cert],
45     require     => File['/usr/local/sbin/bacula-idle-restart'],
46   }
47
48
49   file { '/etc/bacula/bacula-sd.conf':
50     content => template('bacula/bacula-sd.conf.erb'),
51     mode    => '0640',
52     group   => bacula,
53     notify  => Exec['bacula-sd restart-when-idle']
54   }
55
56   file { '/etc/bacula/storage-conf.d':
57     ensure  => directory,
58     mode    => '0755',
59     group   => bacula,
60     purge   => true,
61     force   => true,
62     recurse => true,
63     source  => 'puppet:///files/empty/',
64     notify  => Exec['bacula-sd restart-when-idle']
65   }
66
67   # allow access from director and fds
68   ferm::rule::simple { 'dsa-bacula-sd':
69     description => 'Access to the bacula-storage',
70     port        => $port_sd,
71     target      => 'bacula-sd',
72   }
73   Ferm::Rule::Simple <<| tag == 'bacula::director-to-storage' |>>;
74   Ferm::Rule::Simple <<| tag == "bacula::fd-to-storage::${::fqdn}" |>>;
75
76   file { '/etc/bacula/storage-conf.d/empty.conf':
77     content => '',
78     mode    => '0440',
79     group   => bacula,
80     notify  => Exec['bacula-sd restart-when-idle']
81   }
82
83   package { 'python3-psycopg2': ensure => installed }
84   file { '/usr/local/bin/bacula-unlink-removed-volumes':
85     source => 'puppet:///modules/bacula/bacula-unlink-removed-volumes',
86     mode   => '0555',
87   }
88   file { '/etc/cron.d/puppet-bacula-storage-stuff': ensure => absent, }
89   concat::fragment { 'puppet-crontab--bacula-storage':
90     target  => '/etc/cron.d/puppet-crontab',
91     content => @(EOF)
92       @daily bacula chronic /usr/local/bin/bacula-unlink-removed-volumes -v
93       | EOF
94   }
95
96   Bacula::Storage::Client<<| tag == "bacula::to-storage::${::fqdn}" |>>
97 }