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"
26 basedir = data_bag_item("accounts", username)["home"]
27 web_passwords = data_bag_item("web", "passwords")
29 %w[bin site diffs db src munin].each do |dirname|
30 directory "#{basedir}/#{dirname}" do
38 ## Install overpass from source
40 srcdir = "#{basedir}/src/osm-3s_v#{node[:overpass][:version]}"
51 remote_file "#{srcdir}.tar.gz" do
53 source "https://dev.overpass-api.de/releases/osm-3s_v#{node[:overpass][:version]}.tar.gz"
59 execute "source_tarball" do
61 command "tar -xf #{srcdir}.tar.gz"
63 notifies :run, "execute[install_overpass]"
64 not_if { ::File.exist?(srcdir) }
67 execute "install_overpass" do
71 command "./configure --enable-lz4 --prefix=#{basedir} && make install"
77 gem_binary node[:ruby][:gem]
80 directory "#{basedir}/apache" do
86 template "#{basedir}/apache/totp-filter" do
87 source "totp-filter.erb"
91 variables :totp_key => web_passwords["totp_key"]
94 ssl_certificate node[:fqdn] do
96 node[:overpass][:fqdn]]
97 notifies :reload, "service[apache2]"
101 apache_module "headers"
102 apache_module "rewrite"
104 apache_site "default" do
108 apache_site "#{node[:overpass][:fqdn]}" do
109 template "apache.erb"
110 directory "#{basedir}/site"
111 variables :script_directory => "#{basedir}/cgi-bin"
122 logdir = node[:overpass][:logdir]
131 %w[overpass-update-db overpass-update-areas].each do |fname|
132 template "#{basedir}/bin/#{fname}" do
133 source "#{fname}.erb"
137 variables :basedir => basedir, :srcdir => srcdir
141 template "#{basedir}/bin/overpass-import-db" do
142 source "overpass-import-db.erb"
146 variables :basedir => basedir, :username => username, :srcdir => srcdir
149 systemd_service "overpass-dispatcher" do
150 description "Overpass Main Dispatcher"
151 working_directory basedir
152 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]}"
153 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
154 standard_output "append:#{logdir}/osm_base.log"
158 service "overpass-dispatcher" do
162 systemd_service "overpass-area-dispatcher" do
163 description "Overpass Area Dispatcher"
164 after ["overpass-dispatcher"]
165 working_directory basedir
166 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
167 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
168 standard_output "append:#{logdir}/areas.log"
172 service "overpass-area-dispatcher" do
176 systemd_service "overpass-update" do
177 description "Overpass Update Application"
178 after ["overpass-dispatcher"]
179 working_directory basedir
180 exec_start "#{basedir}/bin/overpass-update-db"
181 standard_output "append:#{logdir}/update.log"
185 if node[:overpass][:meta_mode] == "attic"
186 systemd_service "overpass-area-processor" do
187 description "Overpass Area Processor"
188 after ["overpass-area-dispatcher"]
189 working_directory basedir
190 exec_start "#{basedir}/bin/overpass-update-areas"
191 standard_output "append:#{logdir}/area-processor.log"
196 systemd_service "overpass-area-processor" do
197 description "Overpass Area Processor"
198 after ["overpass-area-dispatcher"]
199 working_directory basedir
200 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
201 standard_input "file:#{srcdir}/rules/areas.osm3s"
202 standard_output "append:#{logdir}/area-processor.log"
208 systemd_timer "overpass-area-processor" do
209 description "Update areas in Overpass"
210 on_calendar "*-*-* *:*:00"
213 service "overpass-area-processor" do
217 template "/etc/logrotate.d/overpass" do
218 source "logrotate.erb"
222 variables :logdir => logdir
227 %w[db_lag request_count].each do |name|
228 template "#{basedir}/munin/overpass_#{name}" do
229 source "munin_#{name}.erb"
233 variables :basedir => basedir
236 munin_plugin "overpass_#{name}" do
237 target "#{basedir}/munin/overpass_#{name}"
239 conf_variables :user => username