5 # Copyright:: 2021, 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 # https://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 "accounts"
21 include_recipe "apache"
22 include_recipe "munin"
23 include_recipe "prometheus"
27 basedir = data_bag_item("accounts", username)["home"]
28 web_passwords = data_bag_item("web", "passwords")
30 %w[bin site diffs db src].each do |dirname|
31 directory "#{basedir}/#{dirname}" do
39 # FIXME: Remove purge post munin removal
40 directory "#{basedir}/munin" do
45 ## Install overpass from source
47 srcdir = "#{basedir}/src/osm-3s_v#{node[:overpass][:version]}"
58 remote_file "#{srcdir}.tar.gz" do
60 source "https://dev.overpass-api.de/releases/osm-3s_v#{node[:overpass][:version]}.tar.gz"
66 execute "source_tarball" do
68 command "tar -xf #{srcdir}.tar.gz"
70 notifies :run, "execute[install_overpass]"
71 not_if { ::File.exist?(srcdir) }
74 execute "install_overpass" do
78 command "./configure --enable-lz4 --prefix=#{basedir} && make install"
79 notifies :restart, "service[overpass-dispatcher]"
80 notifies :restart, "service[overpass-area-dispatcher]"
86 gem_binary node[:ruby][:gem]
89 directory "#{basedir}/apache" do
95 template "#{basedir}/apache/totp-filter" do
96 source "totp-filter.erb"
100 variables :totp_key => web_passwords["totp_key"]
103 ssl_certificate node[:fqdn] do
104 domains [node[:fqdn],
105 node[:overpass][:fqdn]]
106 notifies :reload, "service[apache2]"
110 apache_module "headers"
111 apache_module "rewrite"
113 apache_site "default" do
117 apache_site "#{node[:overpass][:fqdn]}" do
118 template "apache.erb"
119 directory "#{basedir}/site"
120 variables :script_directory => "#{basedir}/cgi-bin"
131 logdir = node[:overpass][:logdir]
140 %w[overpass-update-db overpass-update-areas].each do |fname|
141 template "#{basedir}/bin/#{fname}" do
142 source "#{fname}.erb"
146 variables :basedir => basedir, :srcdir => srcdir
150 template "#{basedir}/bin/overpass-import-db" do
151 source "overpass-import-db.erb"
155 variables :basedir => basedir, :username => username, :srcdir => srcdir
158 systemd_service "overpass-dispatcher" do
159 description "Overpass Main Dispatcher"
160 wants ["overpass-area-dispatcher.service"]
161 working_directory basedir
162 exec_start "#{basedir}/bin/dispatcher --osm-base #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db --rate-limit=#{node[:overpass][:rate_limit]} --space=#{node[:overpass][:dispatcher_space]}"
163 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
164 standard_output "append:#{logdir}/osm_base.log"
168 service "overpass-dispatcher" do
172 systemd_service "overpass-area-dispatcher" do
173 description "Overpass Area Dispatcher"
174 after ["overpass-dispatcher.service"]
175 working_directory basedir
176 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
177 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
178 standard_output "append:#{logdir}/areas.log"
182 service "overpass-area-dispatcher" do
186 systemd_service "overpass-update" do
187 description "Overpass Update Application"
188 after ["overpass-dispatcher.service"]
189 wants ["overpass-area-processor.service"]
190 working_directory basedir
191 exec_start "#{basedir}/bin/overpass-update-db"
192 standard_output "append:#{logdir}/update.log"
197 if node[:overpass][:meta_mode] == "attic"
198 systemd_service "overpass-area-processor" do
199 description "Overpass Area Processor"
200 after ["overpass-area-dispatcher.service", "overpass-update.service"]
201 working_directory basedir
202 exec_start "#{basedir}/bin/overpass-update-areas"
203 standard_output "append:#{logdir}/area-processor.log"
209 systemd_service "overpass-area-processor" do
210 description "Overpass Area Processor"
211 after ["overpass-area-dispatcher.service", "overpass-update.service"]
212 working_directory basedir
213 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
214 standard_input "file:#{srcdir}/rules/areas.osm3s"
215 standard_output "append:#{logdir}/area-processor.log"
222 systemd_timer "overpass-area-processor" do
226 service "overpass-area-processor" do
230 template "/etc/logrotate.d/overpass" do
231 source "logrotate.erb"
235 variables :logdir => logdir
238 prometheus_exporter "overpass" do
241 restrict_address_families "AF_UNIX"
243 "--overpass.base-directory=#{basedir}"