Generate new style piwik configuration
authorTom Hughes <tom@compton.nu>
Sat, 24 Aug 2013 12:09:29 +0000 (13:09 +0100)
committerTom Hughes <tom@compton.nu>
Sat, 24 Aug 2013 13:22:21 +0000 (14:22 +0100)
cookbooks/web/definitions/rails_port.rb
cookbooks/web/recipes/rails.rb

index a51484b..ccf6633 100644 (file)
@@ -17,6 +17,8 @@
 # limitations under the License.
 #
 
+require "yaml"
+
 define :rails_port, :action => [ :create, :enable ] do
   name = params[:name]
   ruby_version = params[:ruby] || "1.9.1"
@@ -217,6 +219,21 @@ define :rails_port, :action => [ :create, :enable ] do
     notifies :touch, resources(:file => "#{rails_directory}/tmp/restart.txt")
   end
 
+  if params[:piwik_configuration]
+    file "#{rails_directory}/config/piwik.yml" do
+      owner rails_user
+      group rails_group
+      mode 0664
+      content YAML.dump(params[:piwik_configuration])
+      notifies :run, resources(:execute => "#{rails_directory}/public/assets")
+    end
+  else
+    file "#{rails_directory}/config/piwik.yml" do
+      action :delete
+      notifies :run, resources(:execute => "#{rails_directory}/public/assets")
+    end
+  end
+
   execute "#{rails_directory}/lib/quad_tile/extconf.rb" do
     command "ruby extconf.rb"
     cwd "#{rails_directory}/lib/quad_tile"
index cd8bb9b..23624b1 100644 (file)
@@ -61,6 +61,10 @@ end
 
 rails_directory = "#{node[:web][:base_directory]}/rails"
 
+piwik_configuration = data_bag_item("web", "piwik").to_hash.reject do |k,v|
+  ["chef_type", "data_bag", "id"].include?(k)
+end
+
 rails_port "www.openstreetmap.org" do
   ruby node[:web][:ruby_version]
   directory rails_directory
@@ -89,4 +93,5 @@ rails_port "www.openstreetmap.org" do
   piwik_location "piwik.openstreetmap.org"
   piwik_site 1
   piwik_signup_goal 1
+  piwik_configuration piwik_configuration
 end