]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/recipes/cgimap.rb
nominatim: enable file-based query log and log rotation
[chef.git] / cookbooks / web / recipes / cgimap.rb
1 #
2 # Cookbook Name:: web
3 # Recipe:: cgimap
4 #
5 # Copyright 2011, OpenStreetMap Foundation
6 #
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
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "tools"
21 include_recipe "web::base"
22
23 db_passwords = data_bag_item("db", "passwords")
24
25 package "gcc"
26 package "make"
27 package "autoconf"
28 package "automake"
29 package "libfcgi-dev"
30 package "libxml2-dev"
31 package "libmemcached-dev"
32 package "libboost-regex-dev"
33 package "libboost-system-dev"
34 package "libboost-program-options-dev"
35 package "libboost-date-time-dev"
36 package "libpqxx3-dev"
37 package "zlib1g-dev"
38
39 cgimap_directory = "#{node[:web][:base_directory]}/cgimap"
40 pid_directory = node[:web][:pid_directory]
41 log_directory = node[:web][:log_directory]
42
43 execute "cgimap-build" do
44   action :nothing
45   command "make"
46   cwd cgimap_directory
47   user "rails"
48   group "rails"
49 end
50
51 execute "cgimap-configure" do
52   action :nothing
53   command "./configure --with-fcgi=/usr --with-boost-libdir=/usr/lib/x86_64-linux-gnu"
54   cwd cgimap_directory
55   user "rails"
56   group "rails"
57   notifies :run, "execute[cgimap-build]", :immediate
58 end
59
60 execute "cgimap-autogen" do
61   action :nothing
62   command "./autogen.sh"
63   cwd cgimap_directory
64   user "rails"
65   group "rails"
66   notifies :run, "execute[cgimap-configure]", :immediate
67 end
68
69 git cgimap_directory do
70   action :sync
71   repository "git://git.openstreetmap.org/cgimap.git"
72   revision "live"
73   user "rails"
74   group "rails"
75   notifies :run, "execute[cgimap-autogen]", :immediate
76 end
77
78 if node[:web][:readonly_database_host]
79   database_host = node[:web][:readonly_database_host]
80   database_readonly = true
81 else
82   database_host = node[:web][:database_host]
83   database_readonly = node[:web][:status] == "database_readonly"
84 end
85
86 cgimap_init = edit_file "#{cgimap_directory}/scripts/cgimap.init" do |line|
87   line.gsub!(/^CGIMAP_HOST=.*;/, "CGIMAP_HOST=#{database_host};")
88   line.gsub!(/^CGIMAP_DBNAME=.*;/, "CGIMAP_DBNAME=openstreetmap;")
89   line.gsub!(/^CGIMAP_USERNAME=.*;/, "CGIMAP_USERNAME=rails;")
90   line.gsub!(/^CGIMAP_PASSWORD=.*;/, "CGIMAP_PASSWORD=#{db_passwords['rails']};")
91   line.gsub!(/^CGIMAP_PIDFILE=.*;/, "CGIMAP_PIDFILE=#{pid_directory}/cgimap.pid;")
92   line.gsub!(/^CGIMAP_LOGFILE=.*;/, "CGIMAP_LOGFILE=#{log_directory}/cgimap.log;")
93   line.gsub!(/^CGIMAP_MEMCACHE=.*;/, "CGIMAP_MEMCACHE=rails1,rails2,rails3;")
94
95   line.gsub!(/\/home\/rails\/bin\/map/, "#{cgimap_directory}/map")
96
97   if database_readonly
98     line.gsub!(/--daemon/, "--daemon --readonly")
99   end
100
101   line
102 end
103
104 file "/etc/init.d/cgimap" do
105   owner "root"
106   group "root"
107   mode 0755
108   content cgimap_init
109 end
110
111 if ["database_offline", "api_offline"].include?(node[:web][:status])
112   service "cgimap" do
113     action :stop
114   end
115 else
116   service "cgimap" do
117     action [ :enable, :start ]
118     supports :restart => true, :reload => true
119     subscribes :restart, "execute[cgimap-build]"
120     subscribes :restart, "file[/etc/init.d/cgimap]"
121   end
122 end