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, "archive_file[#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip]", :immediately
80 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip]", :immediately
81 notifies :run, "notify_group[matomo-updated]"
85 directory "/opt/matomo-#{version}/matomo/config" do
91 template "/opt/matomo-#{version}/matomo/config/config.ini.php" do
96 variables :passwords => passwords,
97 :directory => "/opt/matomo-#{version}/matomo",
98 :plugins => node[:matomo][:plugins].keys.sort
99 notifies :run, "notify_group[matomo-updated]"
102 directory "/opt/matomo-#{version}/matomo/tmp" do
108 directory "/opt/matomo-#{version}/matomo/tmp/assets" do
114 directory "/opt/matomo-#{version}/matomo/tmp/cache" do
120 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-ASN.mmdb" do
121 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
124 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-City.mmdb" do
125 to "#{geoip_directory}/GeoLite2-City.mmdb"
128 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-Country.mmdb" do
129 to "#{geoip_directory}/GeoLite2-Country.mmdb"
132 mysql_user "piwik@localhost" do
133 password passwords["database"]
136 mysql_database "piwik" do
137 permissions "piwik@localhost" => :all
140 notify_group "matomo-updated"
142 if File.symlink?("/srv/matomo.openstreetmap.org")
143 execute "core:update" do
145 command "/opt/matomo-#{version}/matomo/console core:update --yes"
148 subscribes :run, "notify_group[matomo-updated]"
151 execute "custom-matomo-js:update" do
153 command "/opt/matomo-#{version}/matomo/console custom-matomo-js:update"
156 subscribes :run, "execute[core:update]"
159 execute "/opt/matomo-#{version}/matomo/matomo.br" do
161 command "brotli --keep --best /opt/matomo-#{version}/matomo/matomo.js"
162 cwd "/opt/matomo-#{version}"
165 subscribes :run, "execute[custom-matomo-js:update]"
168 execute "/opt/matomo-#{version}/matomo/matomo.js" do
170 command "gzip --keep --best /opt/matomo-#{version}/matomo/matomo.js"
171 cwd "/opt/matomo-#{version}"
174 subscribes :run, "execute[custom-matomo-js:update]"
177 execute "/opt/matomo-#{version}/matomo/piwik.br" do
179 command "brotli --keep --best /opt/matomo-#{version}/matomo/piwik.js"
180 cwd "/opt/matomo-#{version}"
183 subscribes :run, "execute[custom-matomo-js:update]"
186 execute "/opt/matomo-#{version}/matomo/piwik.js" do
188 command "gzip --keep --best /opt/matomo-#{version}/matomo/piwik.js"
189 cwd "/opt/matomo-#{version}"
192 subscribes :run, "execute[custom-matomo-js:update]"
196 link "/srv/matomo.openstreetmap.org" do
197 to "/opt/matomo-#{version}/matomo"
198 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
201 ssl_certificate "matomo.openstreetmap.org" do
202 domains ["matomo.openstreetmap.org", "matomo.osm.org",
203 "piwik.openstreetmap.org", "piwik.osm.org"]
204 notifies :reload, "service[apache2]"
207 php_fpm "matomo.openstreetmap.org" do
211 apache_site "matomo.openstreetmap.org" do
212 template "apache.erb"
218 command "/usr/bin/php /srv/matomo.openstreetmap.org/console core:archive --quiet --url=https://matomo.openstreetmap.org/"