5 # Copyright:: 2011, 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 "apache"
21 include_recipe "geoipupdate"
22 include_recipe "mysql"
23 include_recipe "php::fpm"
25 passwords = data_bag_item("matomo", "passwords")
39 apache_module "expires"
40 apache_module "rewrite"
42 version = node[:matomo][:version]
44 geoip_directory = node[:geoipupdate][:directory]
46 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
47 source "https://builds.matomo.org/matomo-#{version}.zip"
50 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
51 destination "/opt/matomo-#{version}"
52 notifies :run, "notify_group[matomo-updated]"
55 node[:matomo][:plugins].each do |plugin_name, plugin_version|
56 next if plugin_version.nil?
58 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
59 source "https://plugins.matomo.org/api/2.0/plugins/#{plugin_name}/download/#{plugin_version}"
62 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
63 destination "/opt/matomo-#{plugin_name}-#{plugin_version}"
66 link "/opt/matomo-#{version}/matomo/plugins/#{plugin_name}" do
67 to "/opt/matomo-#{plugin_name}-#{plugin_version}/#{plugin_name}"
68 notifies :run, "notify_group[matomo-updated]"
72 directory "/opt/matomo-#{version}/matomo/config" do
78 template "/opt/matomo-#{version}/matomo/config/config.ini.php" do
83 variables :passwords => passwords,
84 :directory => "/opt/matomo-#{version}/matomo",
85 :plugins => node[:matomo][:plugins].keys.sort
86 notifies :run, "notify_group[matomo-updated]"
89 directory "/opt/matomo-#{version}/matomo/tmp" do
95 directory "/opt/matomo-#{version}/matomo/tmp/assets" do
101 directory "/opt/matomo-#{version}/matomo/tmp/cache" do
107 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-ASN.mmdb" do
108 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
111 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-City.mmdb" do
112 to "#{geoip_directory}/GeoLite2-City.mmdb"
115 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-Country.mmdb" do
116 to "#{geoip_directory}/GeoLite2-Country.mmdb"
119 mysql_user "piwik@localhost" do
120 password passwords["database"]
123 mysql_database "piwik" do
124 permissions "piwik@localhost" => :all
127 notify_group "matomo-updated"
129 if File.symlink?("/srv/matomo.openstreetmap.org")
130 execute "core:update" do
132 command "/opt/matomo-#{version}/matomo/console core:update --yes"
135 subscribes :run, "notify_group[matomo-updated]"
138 execute "custom-matomo-js:update" do
140 command "/opt/matomo-#{version}/matomo/console custom-matomo-js:update"
143 subscribes :run, "execute[core:update]"
146 execute "/opt/matomo-#{version}/matomo/matomo.br" do
148 command "brotli --keep --force --best /opt/matomo-#{version}/matomo/matomo.js"
149 cwd "/opt/matomo-#{version}"
152 subscribes :run, "execute[custom-matomo-js:update]"
155 execute "/opt/matomo-#{version}/matomo/matomo.js" do
157 command "gzip --keep --force --best /opt/matomo-#{version}/matomo/matomo.js"
158 cwd "/opt/matomo-#{version}"
161 subscribes :run, "execute[custom-matomo-js:update]"
164 execute "/opt/matomo-#{version}/matomo/piwik.br" do
166 command "brotli --keep --force --best /opt/matomo-#{version}/matomo/piwik.js"
167 cwd "/opt/matomo-#{version}"
170 subscribes :run, "execute[custom-matomo-js:update]"
173 execute "/opt/matomo-#{version}/matomo/piwik.js" do
175 command "gzip --keep --force --best /opt/matomo-#{version}/matomo/piwik.js"
176 cwd "/opt/matomo-#{version}"
179 subscribes :run, "execute[custom-matomo-js:update]"
183 link "/srv/matomo.openstreetmap.org" do
184 to "/opt/matomo-#{version}/matomo"
185 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
188 ssl_certificate "matomo.openstreetmap.org" do
189 domains ["matomo.openstreetmap.org", "matomo.osm.org",
190 "piwik.openstreetmap.org", "piwik.osm.org"]
191 notifies :reload, "service[apache2]"
194 php_fpm "matomo.openstreetmap.org" do
198 apache_site "matomo.openstreetmap.org" do
199 template "apache.erb"
202 systemd_service "matomo-archive" do
203 description "Matomo report archiving"
204 exec_start "/usr/bin/php /srv/matomo.openstreetmap.org/console core:archive --url=https://matomo.openstreetmap.org/"
208 memory_deny_write_execute false
209 restrict_address_families "AF_UNIX"
210 read_write_paths "/opt/matomo-#{version}/matomo/tmp"
213 systemd_timer "matomo-archive" do
214 description "Matomo report archiving"
218 service "matomo-archive.timer" do
219 action [:enable, :start]