]> git.openstreetmap.org Git - chef.git/blob - cookbooks/nominatim/recipes/default.rb
a33fe85c24073c1a6682cde02d8fc8efdc2d2f7d
[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"
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 apache_module "fastcgi-handler"
33
34 home_directory = data_bag_item("accounts", "nominatim")["home"]
35 source_directory = "#{home_directory}/nominatim"
36 email_errors = data_bag_item("accounts", "lonvia")["email"]
37
38 service "php5-fpm" do
39   action [ :enable, :start ]
40   supports :status => true, :restart => true, :reload => true
41 end
42
43 apache_site "nominatim.openstreetmap.org" do
44   template "apache.erb"
45   directory "/home/lonvia/nominatim"
46   variables :pools => node[:nominatim][:fpm_pools]
47 end
48
49 node[:nominatim][:fpm_pools].each do |name,data|
50
51   template "/etc/php5/fpm/pool.d/#{name}.conf" do
52     source "fpm.conf.erb"
53     owner "root"
54     group "root"
55     mode 0644
56     variables data.merge(:name => name)
57     notifies :reload, resources(:service => "php5-fpm")
58   end
59 end
60
61 postgresql_user "tomh" do
62   cluster "9.1/main"
63   superuser true
64 end
65
66 postgresql_user "lonvia" do
67   cluster "9.1/main"
68   superuser true
69 end
70
71 postgresql_user "twain" do
72   cluster "9.1/main"
73   superuser true
74 end
75
76 postgresql_user "nominatim" do
77   cluster "9.1/main"
78   superuser true
79 end
80
81 postgresql_user "www-data" do
82   cluster "9.1/main"
83 end
84
85 postgresql_munin "nominatim" do
86   cluster "9.1/main"
87   database "nominatim"
88 end
89
90 directory "/var/log/nominatim" do
91   owner "nominatim"
92   group "nominatim"
93   mode 0755
94 end
95
96 package "osmosis"
97 package "gcc"
98 package "proj-bin"
99 package "libgeos-c1"
100 package "postgresql-9.1-postgis"
101 package "postgresql-server-dev-9.1"
102 package "build-essential"
103 package "libxml2-dev"
104 package "libgeos-dev"
105 package "libgeos++-dev"
106 package "libpq-dev"
107 package "libbz2-dev"
108 package "libtool"
109 package "automake"
110 package "libproj-dev"
111 package "libprotobuf-c0-dev"
112 package "protobuf-c-compiler"
113
114 execute "php-pear-db" do
115   command "pear install DB"
116   not_if { File.exists?("/usr/share/php/DB") }
117 end
118
119 execute "compile_nominatim" do
120   action :nothing
121   command "cd #{source_directory} && ./autogen.sh && ./configure && make"
122   user "nominatim"
123 end
124
125 git source_directory do
126   action :checkout
127   repository node[:nominatim][:repository]
128   enable_submodules true
129   user "nominatim"
130   group "nominatim"
131   notifies :run, "execute[compile_nominatim]"
132 end
133
134 directory "#{source_directory}/log" do
135   owner "nominatim"
136   group "nominatim"
137   mode 0755
138 end
139
140
141 template "#{source_directory}/.git/hooks/post-merge" do
142   source "update_source.erb"
143   owner  "nominatim"
144   group  "nominatim"
145   mode   0755
146   variables :source_directory => source_directory
147 end
148
149 template "#{source_directory}/settings/local.php" do
150   source "nominatim.erb"
151   owner "nominatim"
152   group "nominatim"
153   mode 0664
154 end
155
156 template "#{source_directory}/settings/ip_blocks.conf" do
157   action :create_if_missing
158   source "ipblocks.erb"
159   owner "nominatim"
160   group "nominatim"
161   mode 0664
162 end
163
164 file "#{source_directory}/settings/apache_blocks.conf" do
165   action :create_if_missing
166   owner "nominatim"
167   group "nominatim"
168   mode 0664
169 end
170
171 file "#{source_directory}/settings/ip_blocks.map" do
172   action :create_if_missing
173   owner "nominatim"
174   group "nominatim"
175   mode 0664
176 end
177
178 cron "nominatim_logrotate" do
179   hour "5"
180   minute "30"
181   weekday "0"
182   command "#{source_directory}/utils/cron_logrotate.sh"
183   user "nominatim"
184   mailto email_errors
185 end
186
187 cron "nominatim_banip" do
188   command "#{source_directory}/utils/cron_banip.sh"
189   user "nominatim"
190   mailto email_errors
191 end
192
193 cron "nominatim_vacuum" do
194   hour "2"
195   minute "00"
196   command "#{source_directory}/utils/cron_vacuum.sh"
197   user "nominatim"
198   mailto email_errors
199 end
200
201 ['search', 'reverse'].each do |filename|
202   ['phpj', 'phpx'].each do |ext|
203     link "#{source_directory}/website/#{filename}.#{ext}" do
204       to "#{source_directory}/website/#{filename}.php"
205       user "nominatim"
206       group "nominatim"
207     end
208   end
209 end
210
211 template "#{source_directory}/utils/nominatim-update" do
212   source "updater.erb"
213   user   "nominatim"
214   group  "nominatim"
215   mode   0755
216 end
217
218 template "/etc/init.d/nominatim-update" do
219   source "updater.init.erb"
220   user   "nominatim"
221   group  "nominatim"
222   mode   0755
223   variables :source_directory => source_directory
224 end
225