5 # Copyright 2011, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # http://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
20 include_recipe "tools"
21 include_recipe "web::base"
23 db_passwords = data_bag_item("db", "passwords")
31 package "libmemcached-dev"
32 package "libboost-regex-dev"
33 package "libboost-program-options-dev"
34 package "libboost-date-time-dev"
37 if node[:lsb][:release].to_f < 12.04
40 package "libpqxx3-dev"
43 cgimap_directory = "#{node[:web][:base_directory]}/cgimap"
44 pid_directory = node[:web][:pid_directory]
45 log_directory = node[:web][:log_directory]
47 execute "cgimap-build" do
55 execute "cgimap-configure" do
57 command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib"
61 notifies :run, resources(:execute => "cgimap-build"), :immediate
64 execute "cgimap-autogen" do
66 command "./autogen.sh"
70 notifies :run, resources(:execute => "cgimap-configure"), :immediate
73 git cgimap_directory do
75 repository "git://git.openstreetmap.org/cgimap.git"
79 notifies :run, resources(:execute => "cgimap-autogen"), :immediate
82 if node[:web][:readonly_database_host]
83 database_host = node[:web][:readonly_database_host]
84 database_readonly = true
86 database_host = node[:web][:database_host]
87 database_readonly = node[:web][:status] == "database_readonly"
90 file "/etc/init.d/cgimap" do
94 content_from_file "#{cgimap_directory}/scripts/cgimap.init" do |line|
95 line.gsub!(/^CGIMAP_HOST=.*;/, "CGIMAP_HOST=#{database_host};")
96 line.gsub!(/^CGIMAP_DBNAME=.*;/, "CGIMAP_DBNAME=openstreetmap;")
97 line.gsub!(/^CGIMAP_USERNAME=.*;/, "CGIMAP_USERNAME=rails;")
98 line.gsub!(/^CGIMAP_PASSWORD=.*;/, "CGIMAP_PASSWORD=#{db_passwords['rails']};")
99 line.gsub!(/^CGIMAP_PIDFILE=.*;/, "CGIMAP_PIDFILE=#{pid_directory}/cgimap.pid;")
100 line.gsub!(/^CGIMAP_LOGFILE=.*;/, "CGIMAP_LOGFILE=#{log_directory}/cgimap.log;")
101 line.gsub!(/^CGIMAP_MEMCACHE=.*;/, "CGIMAP_MEMCACHE=rails1,rails2,rails3;")
103 line.gsub!(/\/home\/rails\/bin\/map/, "#{cgimap_directory}/map")
106 line.gsub!(/--daemon/, "--daemon --readonly")
113 if ["database_offline", "api_offline"].include?(node[:web][:status])
119 action [ :enable, :start ]
120 supports :restart => true, :reload => true
121 subscribes :restart, resources(:execute => "cgimap-build")
122 subscribes :restart, resources(:file => "/etc/init.d/cgimap")