Extract logic from template to recipe.
authorMatt Amos <zerebubuth@gmail.com>
Mon, 20 Jun 2016 18:19:22 +0000 (19:19 +0100)
committerMatt Amos <zerebubuth@gmail.com>
Mon, 3 Oct 2016 12:46:36 +0000 (13:46 +0100)
cookbooks/web/recipes/cgimap.rb
cookbooks/web/templates/default/cgimap.init.erb

index 32b6365..fc1e1f4 100644 (file)
@@ -24,12 +24,29 @@ db_passwords = data_bag_item("db", "passwords")
 
 package "openstreetmap-cgimap-bin"
 
+if node[:web][:readonly_database_host]
+  database_host = node[:web][:readonly_database_host]
+  database_readonly = true
+else
+  database_host = node[:web][:database_host]
+  database_readonly = node[:web][:status] == "database_readonly"
+end
+
+memcached_servers = node[:web][:memcached_servers] || []
+
 template "/etc/init.d/cgimap" do
   owner "root"
   group "root"
   mode 0o755
   source "cgimap.init.erb"
-  variables :db_password => db_passwords["rails"]
+  variables {
+    :db_password => db_passwords["rails"],
+    :pid_directory => node[:web][:pid_directory],
+    :log_directory => node[:web][:log_directory],
+    :database_host => database_host,
+    :database_readonly => database_readonly,
+    :memcached_servers => memcached_servers
+  }
 end
 
 if %w(database_offline api_offline).include?(node[:web][:status])
index a2b25d2..888e10c 100644 (file)
@@ -1,29 +1,14 @@
 #!/bin/bash
 
-<%
-pid_directory = node[:web][:pid_directory]
-log_directory = node[:web][:log_directory]
-
-if node[:web][:readonly_database_host]
-  database_host = node[:web][:readonly_database_host]
-  database_readonly = true
-else
-  database_host = node[:web][:database_host]
-  database_readonly = node[:web][:status] == "database_readonly"
-end
-
-memcached_servers = node[:web][:memcached_servers] || []
-%>
-
-CGIMAP_HOST=<%= database_host %>; export CGIMAP_HOST
+CGIMAP_HOST=<%= @database_host %>; export CGIMAP_HOST
 CGIMAP_DBNAME=openstreetmap; export CGIMAP_DBNAME
 CGIMAP_USERNAME=rails; export CGIMAP_USERNAME
 CGIMAP_PASSWORD=<%= @db_password %>; export CGIMAP_PASSWORD
 
-CGIMAP_PIDFILE=<%= pid_directory + "/cgimap.pid" %>; export CGIMAP_PIDFILE
-CGIMAP_LOGFILE=<%= log_directory + "/cgimap.log" %>; export CGIMAP_LOGFILE
+CGIMAP_PIDFILE=<%= @pid_directory + "/cgimap.pid" %>; export CGIMAP_PIDFILE
+CGIMAP_LOGFILE=<%= @log_directory + "/cgimap.log" %>; export CGIMAP_LOGFILE
 
-CGIMAP_MEMCACHE=<%= memcached_servers.join(",") %>; export CGIMAP_MEMCACHE
+CGIMAP_MEMCACHE=<%= @memcached_servers.join(",") %>; export CGIMAP_MEMCACHE
 CGIMAP_RATELIMIT=204800; export CGIMAP_RATELIMIT
 CGIMAP_MAXDEBT=250; export CGIMAP_MAXDEBT