]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/recipes/default.rb
Update backup expiry script
[chef.git] / cookbooks / nominatim / recipes / default.rb
1 #
2 # Cookbook Name:: nominatim
3 # Recipe:: default
4 #
5 # Copyright 2012, 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 "apache::ssl"
21 include_recipe "postgresql"
22 include_recipe "git"
23
24 package "php5"
25 package "php5-cli"
26 package "php5-pgsql"
27 package "php5-fpm"
28 package "php-pear"
29 package "php-apc"
30
31 apache_module "rewrite"
32
33 if node[:lsb][:release].to_f >= 14.04
34   apache_module "proxy"
35   apache_module "proxy_fcgi"
36 else
37   apache_module "fastcgi-handler"
38 end
39
40 home_directory = data_bag_item("accounts", "nominatim")["home"]
41 source_directory = "#{home_directory}/nominatim"
42 email_errors = data_bag_item("accounts", "lonvia")["email"]
43
44 database_cluster = node[:nominatim][:database][:cluster]
45 database_version = database_cluster.sub(/\/.*/, "")
46 database_name = node[:nominatim][:database][:dbname]
47
48 postgis_version = node[:nominatim][:database][:postgis]
49
50 service "php5-fpm" do
51   if node[:lsb][:release].to_f >= 14.04
52     provider Chef::Provider::Service::Upstart
53   end
54   action [ :enable, :start ]
55   supports :status => true, :restart => true, :reload => true
56 end
57
58 apache_site "nominatim.openstreetmap.org" do
59   template "apache.erb"
60   directory source_directory
61   variables :pools => node[:nominatim][:fpm_pools]
62 end
63
64 apache_site "default" do
65   action [ :disable ]
66 end
67
68 node[:nominatim][:fpm_pools].each do |name,data|
69   template "/etc/php5/fpm/pool.d/#{name}.conf" do
70     source "fpm.conf.erb"
71     owner "root"
72     group "root"
73     mode 0644
74     variables data.merge(:name => name, :port => data[:port])
75     notifies :reload, "service[php5-fpm]"
76   end
77 end
78
79 postgresql_user "tomh" do
80   cluster database_cluster
81   superuser true
82 end
83
84 postgresql_user "lonvia" do
85   cluster database_cluster
86   superuser true
87 end
88
89 postgresql_user "twain" do
90   cluster database_cluster
91   superuser true
92 end
93
94 postgresql_user "nominatim" do
95   cluster database_cluster
96   superuser true
97 end
98
99 postgresql_user "www-data" do
100   cluster database_cluster
101 end
102
103 postgresql_munin "nominatim" do
104   cluster database_cluster
105   database database_name
106 end
107
108 directory "/var/log/nominatim" do
109   owner "nominatim"
110   group "nominatim"
111   mode 0755
112 end
113
114 template "/etc/logrotate.d/nominatim" do
115   source "logrotate.nominatim.erb"
116   owner "root"
117   group "root"
118   mode 0644
119 end
120
121
122 package "osmosis"
123 package "gcc"
124 package "proj-bin"
125 package "libgeos-c1"
126 package "postgresql-#{database_version}-postgis-#{postgis_version}"
127 package "postgresql-server-dev-#{database_version}"
128 package "build-essential"
129 package "libxml2-dev"
130 package "libgeos-dev"
131 package "libgeos++-dev"
132 package "libpq-dev"
133 package "libbz2-dev"
134 package "libtool"
135 package "automake"
136 package "libproj-dev"
137 package "libprotobuf-c0-dev"
138 package "protobuf-c-compiler"
139 package "python-psycopg2"
140
141 execute "php-pear-db" do
142   command "pear install DB"
143   not_if { File.exists?("/usr/share/php/DB") }
144 end
145
146 execute "compile_nominatim" do
147   action :nothing
148   command "cd #{source_directory} && ./autogen.sh && ./configure && make"
149   user "nominatim"
150 end
151
152 git source_directory do
153   action :checkout
154   repository node[:nominatim][:repository]
155   enable_submodules true
156   user "nominatim"
157   group "nominatim"
158   notifies :run, "execute[compile_nominatim]"
159 end
160
161 directory "#{source_directory}/log" do
162   owner "nominatim"
163   group "nominatim"
164   mode 0755
165 end
166
167
168 template "#{source_directory}/.git/hooks/post-merge" do
169   source "update_source.erb"
170   owner  "nominatim"
171   group  "nominatim"
172   mode   0755
173   variables :source_directory => source_directory
174 end
175
176 template "#{source_directory}/settings/local.php" do
177   source "nominatim.erb"
178   owner "nominatim"
179   group "nominatim"
180   mode 0664
181 end
182
183 template "#{source_directory}/settings/ip_blocks.conf" do
184   action :create_if_missing
185   source "ipblocks.erb"
186   owner "nominatim"
187   group "nominatim"
188   mode 0664
189 end
190
191 file "#{source_directory}/settings/apache_blocks.conf" do
192   action :create_if_missing
193   owner "nominatim"
194   group "nominatim"
195   mode 0664
196 end
197
198 file "#{source_directory}/settings/ip_blocks.map" do
199   action :create_if_missing
200   owner "nominatim"
201   group "nominatim"
202   mode 0664
203 end
204
205 if node[:nominatim][:enabled]
206   cron_action = :create
207 else
208   cron_action = :delete
209 end
210
211 cron "nominatim_logrotate" do
212   action cron_action
213   hour "5"
214   minute "30"
215   weekday "0"
216   command "#{source_directory}/utils/cron_logrotate.sh"
217   user "nominatim"
218   mailto email_errors
219 end
220
221 cron "nominatim_banip" do
222   action cron_action
223   command "#{source_directory}/utils/cron_banip.py"
224   user "nominatim"
225   mailto email_errors
226 end
227
228 cron "nominatim_vacuum" do
229   action cron_action
230   hour "2"
231   minute "00"
232   command "#{source_directory}/utils/cron_vacuum.sh"
233   user "nominatim"
234   mailto email_errors
235 end
236
237 template "#{source_directory}/utils/nominatim-update" do
238   source "updater.erb"
239   user   "nominatim"
240   group  "nominatim"
241   mode   0755
242 end
243
244 template "/etc/init.d/nominatim-update" do
245   source "updater.init.erb"
246   user   "nominatim"
247   group  "nominatim"
248   mode   0755
249   variables :source_directory => source_directory
250 end
251
252 munin_plugin_conf "nominatim" do
253   template "munin.erb"
254 end
255
256 munin_plugin "nominatim_importlag" do
257   target "#{source_directory}/munin/nominatim_importlag"
258 end
259
260 munin_plugin "nominatim_query_speed" do
261   target "#{source_directory}/munin/nominatim_query_speed"
262 end
263
264 munin_plugin "nominatim_requests" do
265   target "#{source_directory}/munin/nominatim_requests"
266 end
267
268 munin_plugin "nominatim_throttled_ips" do
269   target "#{source_directory}/munin/nominatim_throttled_ips"
270 end
271
272 template "/usr/local/bin/backup-nominatim" do
273   source "backup-nominatim.erb"
274   owner "root"
275   group "root"
276   mode 0755
277 end
278
279 cron "nominatim_backup" do
280   action cron_action
281   hour "3"
282   minute "00"
283   day "1"
284   command "/usr/local/bin/backup-nominatim"
285   user "nominatim"
286   mailto email_errors
287 end