]> git.donarmstrong.com Git - dsa-puppet.git/commitdiff
Restart bacula-{fd,sd} when idle after cert has been updated
authorTollef Fog Heen <tfheen@err.no>
Sun, 21 Apr 2013 21:38:36 +0000 (23:38 +0200)
committerTollef Fog Heen <tfheen@err.no>
Sun, 21 Apr 2013 21:39:49 +0000 (23:39 +0200)
Only restart when idle, to prevent broken backups.

modules/bacula/files/bacula-idle-restart [new file with mode: 0644]
modules/bacula/manifests/client.pp
modules/bacula/manifests/init.pp
modules/bacula/manifests/storage.pp

diff --git a/modules/bacula/files/bacula-idle-restart b/modules/bacula/files/bacula-idle-restart
new file mode 100644 (file)
index 0000000..2f331aa
--- /dev/null
@@ -0,0 +1,42 @@
+#! /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
index db93aa72c8410dcdc6b08d408c2ee386556796bc..8b2bb4e098ac8754c0eeb2cdcb86a9471878549c 100644 (file)
@@ -16,6 +16,14 @@ class bacula::client inherits bacula {
                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',
index ddaa838df980ae431b653697ccac6e90816e9ac1..7e3c5070a1ad319c888b2b860bb8c77e46175695 100644 (file)
@@ -33,4 +33,10 @@ class bacula {
        $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',
+       }
+
 }
index 5a0132d31352dd15ab81839c17f5a682e32657ea..91aee4194e6f12fa03dfc2221ac3c923b860602b 100644 (file)
@@ -10,15 +10,15 @@ class bacula::storage inherits bacula {
                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',
@@ -34,7 +34,7 @@ class bacula::storage inherits bacula {
                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':
@@ -55,7 +55,7 @@ class bacula::storage inherits bacula {
                content => '',
                mode    => '0440',
                group   => bacula,
-               notify  => Exec['bacula-sd reload']
+               notify  => Exec['bacula-sd restart-when-idle']
        }
 
        Bacula::Storage-per-Node<<| |>>