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 directory "/opt/matomo-#{version}" do
52 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
53 source "https://builds.matomo.org/matomo-#{version}.zip"
56 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
58 destination "/opt/matomo-#{version}"
62 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip]", :immediately
63 notifies :run, "notify_group[matomo-updated]"
66 node[:matomo][:plugins].each do |plugin_name, plugin_version|
67 next if plugin_version.nil?
69 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
70 source "https://plugins.matomo.org/api/2.0/plugins/#{plugin_name}/download/#{plugin_version}"
73 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
75 destination "/opt/matomo-#{version}/matomo/plugins"
79 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip]", :immediately
80 notifies :run, "notify_group[matomo-updated]"
84 directory "/opt/matomo-#{version}/matomo/config" do
90 template "/opt/matomo-#{version}/matomo/config/config.ini.php" do
95 variables :passwords => passwords,
96 :directory => "/opt/matomo-#{version}/matomo",
97 :plugins => node[:matomo][:plugins].keys.sort
98 notifies :run, "notify_group[matomo-updated]"
101 directory "/opt/matomo-#{version}/matomo/tmp" do
107 directory "/opt/matomo-#{version}/matomo/tmp/assets" do
113 directory "/opt/matomo-#{version}/matomo/tmp/cache" do
119 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-ASN.mmdb" do
120 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
123 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-City.mmdb" do
124 to "#{geoip_directory}/GeoLite2-City.mmdb"
127 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-Country.mmdb" do
128 to "#{geoip_directory}/GeoLite2-Country.mmdb"
131 mysql_user "piwik@localhost" do
132 password passwords["database"]
135 mysql_database "piwik" do
136 permissions "piwik@localhost" => :all
139 notify_group "matomo-updated"
141 if File.symlink?("/srv/matomo.openstreetmap.org")
142 execute "core:update" do
144 command "/opt/matomo-#{version}/matomo/console core:update --yes"
147 subscribes :run, "notify_group[matomo-updated]"
150 execute "custom-matomo-js:update" do
152 command "/opt/matomo-#{version}/matomo/console custom-matomo-js:update"
155 subscribes :run, "execute[core:update]"
158 execute "/opt/matomo-#{version}/matomo/matomo.br" do
160 command "brotli -k -9 /opt/matomo-#{version}/matomo/matomo.js"
161 cwd "/opt/matomo-#{version}"
164 subscribes :run, "execute[custom-matomo-js:update]"
167 execute "/opt/matomo-#{version}/matomo/matomo.js" do
169 command "gzip -k -9 /opt/matomo-#{version}/matomo/matomo.js"
170 cwd "/opt/matomo-#{version}"
173 subscribes :run, "execute[custom-matomo-js:update]"
176 execute "/opt/matomo-#{version}/matomo/piwik.br" do
178 command "brotli -k -9 /opt/matomo-#{version}/matomo/piwik.js"
179 cwd "/opt/matomo-#{version}"
182 subscribes :run, "execute[custom-matomo-js:update]"
185 execute "/opt/matomo-#{version}/matomo/piwik.js" do
187 command "gzip -k -9 /opt/matomo-#{version}/matomo/piwik.js"
188 cwd "/opt/matomo-#{version}"
191 subscribes :run, "execute[custom-matomo-js:update]"
195 link "/srv/matomo.openstreetmap.org" do
196 to "/opt/matomo-#{version}/matomo"
197 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
200 ssl_certificate "matomo.openstreetmap.org" do
201 domains ["matomo.openstreetmap.org", "matomo.osm.org",
202 "piwik.openstreetmap.org", "piwik.osm.org"]
203 notifies :reload, "service[apache2]"
206 php_fpm "matomo.openstreetmap.org" do
210 apache_site "matomo.openstreetmap.org" do
211 template "apache.erb"
217 command "/usr/bin/php /srv/matomo.openstreetmap.org/console core:archive --quiet --url=https://matomo.openstreetmap.org/"