]> git.openstreetmap.org Git - chef.git/commitdiff
Rework postgresql ohai plugin as a version 7 plugin
authorTom Hughes <tom@compton.nu>
Wed, 30 Apr 2014 21:49:10 +0000 (22:49 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 30 Apr 2014 21:49:54 +0000 (22:49 +0100)
cookbooks/postgresql/templates/default/ohai.rb.erb

index e3eca3a35c5fa62eb344e6e4afb574018c084cb3..cec796f6fc5874a69ab1ad726e430f30b3ac6ec7 100644 (file)
@@ -1,17 +1,21 @@
-provides "postgresql"
+Ohai.plugin(:Postgresql) do
+  provides "postgresql"
 
-postgresql Mash.new
+  collect_data(:default) do
+    postgresql Mash.new
 
-Dir.glob("/etc/postgresql/*/*/postgresql.conf").each do |conf|
-  cluster = conf.sub("/etc/postgresql/", "").sub("/postgresql.conf", "")
+    Dir.glob("/etc/postgresql/*/*/postgresql.conf").each do |conf|
+      cluster = conf.sub("/etc/postgresql/", "").sub("/postgresql.conf", "")
 
-  postgresql[:clusters] = Mash.new unless postgresql[:clusters]
-  postgresql[:clusters][cluster] = Mash.new unless postgresql[:clusters][cluster]
-  postgresql[:clusters][cluster][:version] = cluster.split("/").first.to_f
+      postgresql[:clusters] = Mash.new unless postgresql[:clusters]
+      postgresql[:clusters][cluster] = Mash.new unless postgresql[:clusters][cluster]
+      postgresql[:clusters][cluster][:version] = cluster.split("/").first.to_f
 
-  IO.foreach(conf) do |line|
-    if line =~ /^ *port *= *([0-9]+)\s+/
-      postgresql[:clusters][cluster][:port] = $1
+      IO.foreach(conf) do |line|
+        if line =~ /^ *port *= *([0-9]+)\s+/
+          postgresql[:clusters][cluster][:port] = $1
+        end
+      end
     end
   end
 end