Jcrespo has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/273958

Change subject: [WIP]Update haproxy default file, as it cannot be dynamic in 
jessie
......................................................................

[WIP]Update haproxy default file, as it cannot be dynamic in jessie

As in jessie the default config file cannot be a script, but only a
set of key-value pairs, we need to generate it automatically.

While generally that should as easy to run the generate_default_
haproxy.sh included, for backwards compatibility we need to monitor
files outside of puppet, or outside of this class to refresh that
file.

Bug: T125027
Change-Id: If2dd396fc7bfc38201337b9d318f12e69dc2519e
---
A modules/haproxy/files/generate_haproxy_default.sh
M modules/haproxy/manifests/init.pp
D modules/haproxy/templates/default.erb
3 files changed, 34 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/58/273958/1

diff --git a/modules/haproxy/files/generate_haproxy_default.sh 
b/modules/haproxy/files/generate_haproxy_default.sh
new file mode 100644
index 0000000..b054f47
--- /dev/null
+++ b/modules/haproxy/files/generate_haproxy_default.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+DEFAULT_FILE=/etc/default/haproxy
+echo "ENABLED=1" > $DEFAULT_FILE
+
+EXTRAOPTS=""
+
+for file in $(ls -1 /etc/haproxy/conf.d); do
+    EXTRAOPTS="${EXTRAOPTS} -f /etc/haproxy/conf.d/${file}"
+done
+echo "EXTRAOPTS=\"${EXTRAOPTS}\"" >> $DEFAULT_FILE
diff --git a/modules/haproxy/manifests/init.pp 
b/modules/haproxy/manifests/init.pp
index 6e0dfaa..5975449 100644
--- a/modules/haproxy/manifests/init.pp
+++ b/modules/haproxy/manifests/init.pp
@@ -1,7 +1,7 @@
 # Class haproxy
 
 class haproxy(
-    $template  = 'haproxy/haproxy.cfg.erb',
+    $template = 'haproxy/haproxy.cfg.erb',
 ) {
 
     package { [
@@ -18,20 +18,13 @@
         mode   => '0755',
     }
 
-    file { '/etc/default/haproxy':
-        ensure  => present,
-        mode    => '0444',
-        owner   => 'root',
-        group   => 'root',
-        content => template('haproxy/default.erb'),
-    }
-
     file { '/etc/haproxy/haproxy.cfg':
         ensure  => present,
         mode    => '0444',
         owner   => 'root',
         group   => 'root',
         content => template($template),
+        notify  => Exec['/usr/local/bin/generate_haproxy_default.sh'],
     }
 
     file { '/usr/lib/nagios/plugins/check_haproxy':
@@ -41,6 +34,28 @@
         source => 'puppet:///modules/haproxy/check_haproxy',
     }
 
+    # if any haproxy config file (including those outside of this class) is 
changed,
+    # update the haproxy config (but do not refresh the service immediatelly)
+    file { '/usr/local/bin/generate_haproxy_default.sh':
+        owner  => 'root',
+        group  => 'root',
+        mode   => '0755',
+        source => 'puppet:///modules/haproxy/generate_haproxy_default.sh',
+        notify => Exec['/usr/local/bin/generate_haproxy_default.sh'],
+    }
+
+    exec { '/usr/local/bin/generate_haproxy_default.sh':
+        refreshonly => true,
+    }
+
+    exec { '/tmp/haproxy-config-checksum':
+        command => 'find /etc/haproxy/ -name "*.cfg" | xargs md5sum > 
/tmp/haproxy-config-checksum',
+    }
+
+    file { '/tmp/haproxy-config-checksum':
+        notify  => Exec['/usr/local/bin/generate_haproxy_default.sh']
+    }
+
     nrpe::monitor_service { 'haproxy':
         description  => 'haproxy process',
         nrpe_command => '/usr/lib/nagios/plugins/check_procs -c 1: -C haproxy',
diff --git a/modules/haproxy/templates/default.erb 
b/modules/haproxy/templates/default.erb
deleted file mode 100644
index cbc3f3f..0000000
--- a/modules/haproxy/templates/default.erb
+++ /dev/null
@@ -1,6 +0,0 @@
-ENABLED=1
-
-EXTRAOPTS=""
-for file in $(ls -1 /etc/haproxy/conf.d); do
-    EXTRAOPTS="${EXTRAOPTS} -f /etc/haproxy/conf.d/${file}"
-done
\ No newline at end of file

-- 
To view, visit https://gerrit.wikimedia.org/r/273958
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If2dd396fc7bfc38201337b9d318f12e69dc2519e
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: Jcrespo <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to