Make bacula-idle-restart not be a template anymore. We can just pass all the relevan...
authorPeter Palfrader <peter@palfrader.org>
Tue, 24 Sep 2019 07:10:15 +0000 (09:10 +0200)
committerPeter Palfrader <peter@palfrader.org>
Tue, 24 Sep 2019 07:10:48 +0000 (09:10 +0200)
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
modules/bacula/templates/bacula-idle-restart.erb [deleted file]

diff --git a/modules/bacula/files/bacula-idle-restart b/modules/bacula/files/bacula-idle-restart
new file mode 100644 (file)
index 0000000..cebce07
--- /dev/null
@@ -0,0 +1,37 @@
+#! /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 [ "$#" != 2 ];then
+  echo >&2 "$0 <port> <service>"
+  echo "Restart bacula service when port idle"
+  exit 1
+fi
+
+PORT="$1"
+SERVICE="$2"
+
+# 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 $SERVICE restart
index dfeb176..f46cc02 100644 (file)
@@ -62,7 +62,7 @@ class bacula::client(
 
   exec { 'bacula-fd restart-when-idle':
     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
-    command     => 'sh -c "setsid /usr/local/sbin/bacula-idle-restart fd &"',
+    command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${bacula::bacula_client_port} bacula-fd &'",
     refreshonly => true,
     subscribe   => [ File[$bacula::bacula_ssl_server_cert], File[$bacula::bacula_ssl_client_cert] ],
     require     => File['/usr/local/sbin/bacula-idle-restart'],
index 128063f..6c1b9e2 100644 (file)
@@ -37,7 +37,7 @@ class bacula (
   Array[Stdlib::IP::Address] $public_addresses = $base::public_addresses,
 ) {
   file { '/usr/local/sbin/bacula-idle-restart':
-    mode    => '0555',
-    content => template('bacula/bacula-idle-restart.erb'),
+    mode   => '0555',
+    source => 'puppet:///modules/bacula/bacula-idle-restart',
   }
 }
index 3d9ac3b..8f549d5 100644 (file)
@@ -19,7 +19,7 @@ class bacula::storage inherits bacula {
 
   exec { 'bacula-sd restart-when-idle':
     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
-    command     => 'sh -c "setsid /usr/local/sbin/bacula-idle-restart sd &"',
+    command     => "sh -c 'setsid /usr/local/sbin/bacula-idle-restart ${bacula::bacula_storage_port} bacula-sd &'",
     refreshonly => true,
     subscribe   => File[$bacula::bacula_ssl_server_cert],
     require     => File['/usr/local/sbin/bacula-idle-restart'],
diff --git a/modules/bacula/templates/bacula-idle-restart.erb b/modules/bacula/templates/bacula-idle-restart.erb
deleted file mode 100644 (file)
index a99ff80..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-#! /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=<%= @bacula_client_port %>
-    DIR="bacula-fd"
-elif [ "$1" = "sd" ]; then
-    PORT=<%= @bacula_storage_port %>
-    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