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 "prometheus"
26 basedir = data_bag_item("accounts", username)["home"]
27 web_passwords = data_bag_item("web", "passwords")
29 %w[bin site diffs db src].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
52 action :create_if_missing
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"
72 notifies :restart, "service[overpass-dispatcher]"
73 notifies :restart, "service[overpass-area-dispatcher]"
79 gem_binary node[:ruby][:gem]
82 directory "#{basedir}/apache" do
88 template "#{basedir}/apache/totp-filter" do
89 source "totp-filter.erb"
93 variables :totp_key => web_passwords["totp_key"]
96 ssl_certificate node[:fqdn] do
98 node[:overpass][:fqdn]]
99 notifies :reload, "service[apache2]"
103 apache_module "headers"
104 apache_module "rewrite"
106 apache_site "default" do
110 apache_site "#{node[:overpass][:fqdn]}" do
111 template "apache.erb"
112 directory "#{basedir}/site"
113 variables :script_directory => "#{basedir}/cgi-bin"
124 logdir = node[:overpass][:logdir]
133 %w[overpass-update-db overpass-update-areas].each do |fname|
134 template "#{basedir}/bin/#{fname}" do
135 source "#{fname}.erb"
139 variables :basedir => basedir, :srcdir => srcdir
143 template "#{basedir}/bin/overpass-import-db" do
144 source "overpass-import-db.erb"
148 variables :basedir => basedir, :username => username, :srcdir => srcdir
151 systemd_service "overpass-dispatcher" do
152 description "Overpass Main Dispatcher"
153 wants ["overpass-area-dispatcher.service"]
154 working_directory basedir
155 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]}"
156 exec_stop "#{basedir}/bin/dispatcher --osm-base --terminate"
157 standard_output "append:#{logdir}/osm_base.log"
161 service "overpass-dispatcher" do
165 systemd_service "overpass-area-dispatcher" do
166 description "Overpass Area Dispatcher"
167 after ["overpass-dispatcher.service"]
168 working_directory basedir
169 exec_start "#{basedir}/bin/dispatcher --areas #{meta_map_short[node[:overpass][:meta_mode]]} --db-dir=#{basedir}/db"
170 exec_stop "#{basedir}/bin/dispatcher --areas --terminate"
171 standard_output "append:#{logdir}/areas.log"
175 service "overpass-area-dispatcher" do
179 systemd_service "overpass-update" do
180 description "Overpass Update Application"
181 after ["overpass-dispatcher.service"]
182 wants ["overpass-area-processor.service"]
183 working_directory basedir
184 exec_start "#{basedir}/bin/overpass-update-db"
185 standard_output "append:#{logdir}/update.log"
190 if node[:overpass][:meta_mode] == "attic"
191 systemd_service "overpass-area-processor" do
192 description "Overpass Area Processor"
193 after ["overpass-area-dispatcher.service", "overpass-update.service"]
194 working_directory basedir
195 exec_start "#{basedir}/bin/overpass-update-areas"
196 standard_output "append:#{logdir}/area-processor.log"
202 systemd_service "overpass-area-processor" do
203 description "Overpass Area Processor"
204 after ["overpass-area-dispatcher.service", "overpass-update.service"]
205 working_directory basedir
206 exec_start "#{basedir}/bin/osm3s_query --progress --rules"
207 standard_input "file:#{srcdir}/rules/areas.osm3s"
208 standard_output "append:#{logdir}/area-processor.log"
215 systemd_timer "overpass-area-processor" do
219 service "overpass-area-processor" do
223 template "/etc/logrotate.d/overpass" do
224 source "logrotate.erb"
228 variables :logdir => logdir
231 prometheus_exporter "overpass" do
234 restrict_address_families "AF_UNIX"
236 "--overpass.base-directory=#{basedir}"