From: Tollef Fog Heen Date: Sun, 21 Apr 2013 21:38:36 +0000 (+0200) Subject: Restart bacula-{fd,sd} when idle after cert has been updated X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=a5ffcf93be9b9c03cb2cb20ddcfbfd32b56a8634;p=mirror%2Fdsa-puppet.git Restart bacula-{fd,sd} when idle after cert has been updated Only restart when idle, to prevent broken backups. --- diff --git a/modules/bacula/files/bacula-idle-restart b/modules/bacula/files/bacula-idle-restart new file mode 100644 index 000000000..2f331aaae --- /dev/null +++ b/modules/bacula/files/bacula-idle-restart @@ -0,0 +1,42 @@ +#! /bin/sh -e + +# Written by Tollef Fog Heen +# 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 +# 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 diff --git a/modules/bacula/manifests/client.pp b/modules/bacula/manifests/client.pp index db93aa72c..8b2bb4e09 100644 --- a/modules/bacula/manifests/client.pp +++ b/modules/bacula/manifests/client.pp @@ -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', diff --git a/modules/bacula/manifests/init.pp b/modules/bacula/manifests/init.pp index ddaa838df..7e3c5070a 100644 --- a/modules/bacula/manifests/init.pp +++ b/modules/bacula/manifests/init.pp @@ -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', + } + } diff --git a/modules/bacula/manifests/storage.pp b/modules/bacula/manifests/storage.pp index 5a0132d31..91aee4194 100644 --- a/modules/bacula/manifests/storage.pp +++ b/modules/bacula/manifests/storage.pp @@ -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<<| |>>