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 "munin"
22 include_recipe "apache"
25 basedir = data_bag_item("accounts", username)["home"]
26 web_passwords = data_bag_item("web", "passwords")
28 %w[bin site diffs db src munin].each do |dirname|
29 directory "#{basedir}/#{dirname}" do
37 ## Install overpass from source
39 srcdir = "#{basedir}/src/osm-3s_v#{node[:overpass][:version]}"
50 remote_file "#{srcdir}.tar.gz" do
52 source "https://dev.overpass-api.de/releases/osm-3s_v#{node[:overpass][:version]}.tar.gz"
58 execute "source_tarball" do
60 command "tar -xf #{srcdir}.tar.gz"
62 notifies :run, "execute[install_overpass]"
63 not_if { ::File.exist?(srcdir) }
66 execute "install_overpass" do
70 command "./configure --enable-lz4 --prefix=#{basedir} && make install"
77 directory "#{basedir}/apache" do
83 template "#{basedir}/apache/totp-filter" do
84 source "totp-filter.erb"
88 variables :totp_key => web_passwords["totp_key"]
91 ssl_certificate node[:fqdn] do
93 node[:overpass][:fqdn]]
94 notifies :reload, "service[apache2]"
98 apache_module "headers"
99 apache_module "rewrite"
101 apache_site "default" do
105 apache_site "#{node[:overpass][:fqdn]}" do
106 template "apache.erb"
107 directory "#{basedir}/site"
108 variables :script_directory => "#{basedir}/cgi-bin"
119 logdir = node[:overpass][:logdir]
128 %w[overpass-update-db overpass-update-areas].each do |fname|
129 template "#{basedir}/bin/#{fname}" do
130 source "#{fname}.erb"
134 variables :basedir => basedir, :srcdir => srcdir
138 template "#{basedir}/bin/overpass-import-db" do
139 source "overpass-import-db.erb"
143 variables :basedir => basedir, :username => username, :srcdir => srcdir
146 systemd_service "overpass-dispatcher" do
147 description "Overpass Main Dispatcher"
148 working_directory basedir
149 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]}"
150 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
151 standard_output "append:#{logdir}/osm_base.log"
155 service "overpass-dispatcher" do
159 systemd_service "overpass-area-dispatcher" do
160 description "Overpass Area Dispatcher"
161 after ["overpass-dispatcher"]
162 working_directory basedir
163 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
164 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
165 standard_output "append:#{logdir}/areas.log"
169 service "overpass-area-dispatcher" do
173 systemd_service "overpass-update" do
174 description "Overpass Update Application"
175 after ["overpass-dispatcher"]
176 working_directory basedir
177 exec_start "#{basedir}/bin/overpass-update-db"
178 standard_output "append:#{logdir}/update.log"
182 if node[:overpass][:meta_mode] == "attic"
183 systemd_service "overpass-area-processor" do
184 description "Overpass Area Processor"
185 after ["overpass-area-dispatcher"]
186 working_directory basedir
187 exec_start "#{basedir}/bin/overpass-update-areas"
188 standard_output "append:#{logdir}/area-processor.log"
193 systemd_service "overpass-area-processor" do
194 description "Overpass Area Processor"
195 after ["overpass-area-dispatcher"]
196 working_directory basedir
197 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
198 standard_input "file:#{srcdir}/rules/areas.osm3s"
199 standard_output "append:#{logdir}/area-processor.log"
205 systemd_timer "overpass-area-processor" do
206 description "Update areas in Overpass"
207 on_calendar "*-*-* *:*:00"
210 service "overpass-area-processor" do
216 %w[db_lag request_count].each do |name|
217 template "#{basedir}/munin/overpass_#{name}" do
218 source "munin_#{name}.erb"
222 variables :basedir => basedir
225 munin_plugin "overpass_#{name}" do
226 target "#{basedir}/munin/overpass_#{name}"
228 conf_variables :user => username