]> git.openstreetmap.org Git - chef.git/blob - cookbooks/taginfo/recipes/default.rb
spamassassin: Use correct daemon name on Ubuntu 24.04
[chef.git] / cookbooks / taginfo / recipes / default.rb
1 #
2 # Cookbook:: taginfo
3 # Recipe:: default
4 #
5 # Copyright:: 2014, 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 #     https://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 require "json"
21
22 include_recipe "accounts"
23 include_recipe "apache"
24 include_recipe "git"
25 include_recipe "passenger"
26 include_recipe "planet::current"
27 include_recipe "prometheus"
28 include_recipe "ruby"
29
30 package %w[
31   libsqlite3-dev
32   zlib1g-dev
33   libbz2-dev
34   libboost-dev
35   libexpat1-dev
36   libsparsehash-dev
37   libgd-dev
38   libicu-dev
39   libboost-program-options-dev
40   libosmium2-dev
41   libprotozero-dev
42   cmake
43   make
44   g++
45 ]
46
47 package %w[
48   sqlite3
49   libsqlite3-dev
50   osmium-tool
51   pyosmium
52   curl
53   pbzip2
54 ]
55
56 if (platform?("debian") && node[:lsb][:release].to_f < 13) || (platform?("ubuntu") && node[:lsb][:release].to_f < 24.04)
57   package "sqlite3-pcre" # https://github.com/taginfo/taginfo/issues/436
58 end
59
60 apache_module "cache"
61 apache_module "cache_disk"
62 apache_module "headers"
63
64 directory "/var/log/taginfo" do
65   owner "taginfo"
66   group "taginfo"
67   mode "755"
68 end
69
70 template "/etc/sudoers.d/taginfo" do
71   source "sudoers.erb"
72   owner "root"
73   group "root"
74   mode "440"
75 end
76
77 systemd_service "taginfo-update@" do
78   description "Taginfo update for %i"
79   wants "planet-update.service"
80   after "planet-update.service"
81   exec_start "/srv/%i/bin/update"
82   user "taginfo"
83   sandbox :enable_network => true
84   restrict_address_families "AF_UNIX"
85   read_write_paths [
86     "/srv/%i/data",
87     "/srv/%i/download",
88     "/srv/%i/sources",
89     "/var/log/taginfo/%i"
90   ]
91   nice 10
92 end
93
94 systemd_timer "taginfo-update@" do
95   description "Taginfo update for %i"
96   on_calendar "01:37"
97 end
98
99 node[:taginfo][:sites].each do |site|
100   site_name = site[:name]
101   site_aliases = Array(site[:aliases])
102   directory = site[:directory] || "/srv/#{site_name}"
103   description = site[:description]
104   about = site[:about]
105   icon = site[:icon]
106   contact = site[:contact]
107
108   directory "/var/log/taginfo/#{site_name}" do
109     owner "taginfo"
110     group "taginfo"
111     mode "755"
112   end
113
114   directory directory do
115     owner "taginfo"
116     group "taginfo"
117     mode "755"
118   end
119
120   git "#{directory}/taginfo-tools" do
121     action :sync
122     repository "https://github.com/taginfo/taginfo-tools.git"
123     revision "osmorg-taginfo-live"
124     depth 1
125     enable_submodules true
126     user "taginfo"
127     group "taginfo"
128   end
129
130   directory "#{directory}/build" do
131     owner "taginfo"
132     group "taginfo"
133     mode "755"
134   end
135
136   execute "compile_taginfo_tools" do
137     action :nothing
138     user "taginfo"
139     group "taginfo"
140     cwd "#{directory}/build"
141     command "cmake #{directory}/taginfo-tools -DCMAKE_BUILD_TYPE=Release && make"
142     subscribes :run, "apt_package[libprotozero-dev]"
143     subscribes :run, "apt_package[libosmium2-dev]"
144     subscribes :run, "git[#{directory}/taginfo-tools]"
145   end
146
147   git "#{directory}/taginfo" do
148     action :sync
149     repository "https://github.com/taginfo/taginfo.git"
150     revision "osmorg-taginfo-live"
151     depth 1
152     user "taginfo"
153     group "taginfo"
154   end
155
156   settings = Chef::DelayedEvaluator.new do
157     settings = JSON.parse(IO.read("#{directory}/taginfo/taginfo-config-example.json"))
158
159     settings["instance"]["url"] = "https://#{site_name}/"
160     settings["instance"]["description"] = description
161     settings["instance"]["about"] = about
162     settings["instance"]["icon"] = "/img/logo/#{icon}.png"
163     settings["instance"]["contact"] = contact
164     settings["instance"]["access_control_allow_origin"] = ""
165     settings["logging"]["directory"] = "/var/log/taginfo/#{site_name}"
166     settings["opensearch"]["shortname"] = "Taginfo"
167     settings["opensearch"]["contact"] = "webmaster@openstreetmap.org"
168     settings["paths"]["bin_dir"] = "#{directory}/build/src"
169     settings["sources"]["download"] = ""
170     settings["sources"]["create"] = "db languages projects wiki wikidata chronology sw"
171     settings["sources"]["db"]["planetfile"] = "/var/lib/planet/planet.osh.pbf"
172     settings["sources"]["chronology"]["osm_history_file"] = "/var/lib/planet/planet.osh.pbf"
173     settings["tagstats"]["geodistribution"] = "DenseMmapArray"
174
175     JSON.pretty_generate(settings)
176   end
177
178   file "#{directory}/taginfo-config.json" do
179     owner "taginfo"
180     group "taginfo"
181     mode "644"
182     content settings
183     notifies :restart, "service[apache2]"
184   end
185
186   bundle_config "#{directory}/taginfo" do
187     user "taginfo"
188     group "taginfo"
189     settings "deployment" => "true",
190              "without" => "development:test"
191   end
192
193   bundle_install "#{directory}/taginfo" do
194     action :nothing
195     user "taginfo"
196     group "taginfo"
197     subscribes :run, "git[#{directory}/taginfo]"
198     notifies :restart, "passenger_application[#{directory}/taginfo/web/public]"
199   end
200
201   %w[taginfo/web/tmp bin data data/old download sources].each do |dir|
202     directory "#{directory}/#{dir}" do
203       owner "taginfo"
204       group "taginfo"
205       mode "755"
206     end
207   end
208
209   template "#{directory}/bin/update" do
210     source "update.erb"
211     owner "taginfo"
212     group "taginfo"
213     mode "755"
214     variables :name => site_name, :directory => directory
215   end
216
217   passenger_application "#{directory}/taginfo/web/public" do
218     action :nothing
219   end
220
221   ssl_certificate site_name do
222     domains [site_name] + site_aliases
223     notifies :reload, "service[apache2]"
224   end
225
226   apache_site site_name do
227     template "apache.erb"
228     directory "#{directory}/taginfo/web/public"
229     variables :aliases => site_aliases
230   end
231
232   service "taginfo-update@#{site_name}.timer" do
233     action [:enable, :start]
234   end
235
236   prometheus_collector "taginfo-#{site_name}" do
237     interval "15m"
238     user "taginfo"
239     path node[:ruby][:bundle]
240     options "exec sources/metrics.rb #{directory}/data"
241     working_directory "#{directory}/taginfo"
242   end
243 end