Only restart when idle, to prevent broken backups.
--- /dev/null
+#! /bin/sh -e
+
+# Written by Tollef Fog Heen <tfheen@err.no>
+# Based on code by Peter Palfrader
+#
+# Restart the given bacula director when it's idle.
+#
+# XXX: Add locking
+
+set -e
+
+if [ "$1" = "fd" ];then
+ PORT=9102
+ DIR="bacula-fd"
+elif [ "$1" = "sd" ]; then
+ PORT=9103
+ DIR="bacula-sd"
+else
+ # Usage
+ echo "$0 [fd|sd]"
+ echo
+ echo "Restart bacula fd or sd when idle"
+ exit 1
+fi
+
+# chk_net <port>
+# returns true (0) if there are connections to that port.
+chk_net() {
+ local port="$1"; shift
+ local con="$(ss -nt "sport = :$port" | wc -l)"
+ if [ "$con" -gt 1 ]; then
+ return 0
+ else
+ return 1
+ fi
+}
+
+while chk_net "$PORT"; do
+ sleep 5
+done
+
+service $DIR restart
require => Package['bacula-fd']
}
+ exec { 'bacula-fd restart-when-idle':
+ path => '/usr/bin:/usr/sbin:/bin:/sbin',
+ command => '(setsid /usr/local/sbin/bacula-idle-restart fd &)',
+ refreshonly => true,
+ subscribe => File['/etc/ssl/debian/certs/thishost.crt'],
+ require => File['/usr/local/sbin/bacula-idle-restart'],
+ }
+
file { '/etc/bacula/bacula-fd.conf':
content => template('bacula/bacula-fd.conf.erb'),
mode => '0640',
$bacula_ssl_client_key = '/etc/ssl/debian/keys/thishost.key'
$bacula_ssl_server_cert = '/etc/ssl/debian/certs/thishost-server.crt'
$bacula_ssl_server_key = '/etc/ssl/debian/keys/thishost-server.key'
+
+ file { '/usr/local/sbin/bacula-idle-restart':
+ mode => '0555',
+ source => 'puppet:///modules/bacula/postbaculajob',
+ }
+
}
hasstatus => true,
}
- # should wait on -sd to finish current backups, then restart
- # since it does not support reload and restarting kills running
- # jobs
- exec { 'bacula-sd reload':
+ exec { 'bacula-sd restart-when-idle':
path => '/usr/bin:/usr/sbin:/bin:/sbin',
- command => '/bin/true',
+ command => '(setsid /usr/local/sbin/bacula-idle-restart sd &)',
refreshonly => true,
+ subscribe => File['/etc/ssl/debian/certs/thishost.crt'],
+ require => File['/usr/local/sbin/bacula-idle-restart'],
}
+
file { '/etc/bacula/bacula-sd.conf':
content => template('bacula/bacula-sd.conf.erb'),
mode => '0640',
force => true,
recurse => true,
source => 'puppet:///files/empty/',
- notify => Exec['bacula-sd reload']
+ notify => Exec['bacula-sd restart-when-idle']
}
@ferm::rule { 'dsa-bacula-sd-v4':
content => '',
mode => '0440',
group => bacula,
- notify => Exec['bacula-sd reload']
+ notify => Exec['bacula-sd restart-when-idle']
}
Bacula::Storage-per-Node<<| |>>