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-#{version}/matomo/plugins"
65 notifies :run, "notify_group[matomo-updated]"
69 directory "/opt/matomo-#{version}/matomo/config" do
75 template "/opt/matomo-#{version}/matomo/config/config.ini.php" do
80 variables :passwords => passwords,
81 :directory => "/opt/matomo-#{version}/matomo",
82 :plugins => node[:matomo][:plugins].keys.sort
83 notifies :run, "notify_group[matomo-updated]"
86 directory "/opt/matomo-#{version}/matomo/tmp" do
92 directory "/opt/matomo-#{version}/matomo/tmp/assets" do
98 directory "/opt/matomo-#{version}/matomo/tmp/cache" do
104 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-ASN.mmdb" do
105 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
108 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-City.mmdb" do
109 to "#{geoip_directory}/GeoLite2-City.mmdb"
112 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-Country.mmdb" do
113 to "#{geoip_directory}/GeoLite2-Country.mmdb"
116 mysql_user "piwik@localhost" do
117 password passwords["database"]
120 mysql_database "piwik" do
121 permissions "piwik@localhost" => :all
124 notify_group "matomo-updated"
126 if File.symlink?("/srv/matomo.openstreetmap.org")
127 execute "core:update" do
129 command "/opt/matomo-#{version}/matomo/console core:update --yes"
132 subscribes :run, "notify_group[matomo-updated]"
135 execute "custom-matomo-js:update" do
137 command "/opt/matomo-#{version}/matomo/console custom-matomo-js:update"
140 subscribes :run, "execute[core:update]"
143 execute "/opt/matomo-#{version}/matomo/matomo.br" do
145 command "brotli --keep --force --best /opt/matomo-#{version}/matomo/matomo.js"
146 cwd "/opt/matomo-#{version}"
149 subscribes :run, "execute[custom-matomo-js:update]"
152 execute "/opt/matomo-#{version}/matomo/matomo.js" do
154 command "gzip --keep --force --best /opt/matomo-#{version}/matomo/matomo.js"
155 cwd "/opt/matomo-#{version}"
158 subscribes :run, "execute[custom-matomo-js:update]"
161 execute "/opt/matomo-#{version}/matomo/piwik.br" do
163 command "brotli --keep --force --best /opt/matomo-#{version}/matomo/piwik.js"
164 cwd "/opt/matomo-#{version}"
167 subscribes :run, "execute[custom-matomo-js:update]"
170 execute "/opt/matomo-#{version}/matomo/piwik.js" do
172 command "gzip --keep --force --best /opt/matomo-#{version}/matomo/piwik.js"
173 cwd "/opt/matomo-#{version}"
176 subscribes :run, "execute[custom-matomo-js:update]"
180 link "/srv/matomo.openstreetmap.org" do
181 to "/opt/matomo-#{version}/matomo"
182 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
185 ssl_certificate "matomo.openstreetmap.org" do
186 domains ["matomo.openstreetmap.org", "matomo.osm.org",
187 "piwik.openstreetmap.org", "piwik.osm.org"]
188 notifies :reload, "service[apache2]"
191 php_fpm "matomo.openstreetmap.org" do
195 apache_site "matomo.openstreetmap.org" do
196 template "apache.erb"
202 command "/usr/bin/php /srv/matomo.openstreetmap.org/console core:archive --quiet --url=https://matomo.openstreetmap.org/"