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")
37 apache_module "expires"
38 apache_module "rewrite"
40 version = node[:matomo][:version]
42 geoip_directory = node[:geoipupdate][:directory]
44 directory "/opt/matomo-#{version}" do
50 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
51 source "https://builds.matomo.org/matomo-#{version}.zip"
54 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
56 destination "/opt/matomo-#{version}"
60 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip]", :immediately
61 notifies :run, "notify_group[matomo-updated]"
64 node[:matomo][:plugins].each do |plugin_name, plugin_version|
65 next if plugin_version.nil?
67 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
68 source "https://plugins.matomo.org/api/2.0/plugins/#{plugin_name}/download/#{plugin_version}"
71 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
73 destination "/opt/matomo-#{version}/matomo/plugins"
77 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip]", :immediately
78 notifies :run, "notify_group[matomo-updated]"
82 directory "/opt/matomo-#{version}/matomo/config" do
88 template "/opt/matomo-#{version}/matomo/config/config.ini.php" do
93 variables :passwords => passwords,
94 :directory => "/opt/matomo-#{version}/matomo",
95 :plugins => node[:matomo][:plugins].keys.sort
96 notifies :run, "notify_group[matomo-updated]"
99 directory "/opt/matomo-#{version}/matomo/tmp" do
105 directory "/opt/matomo-#{version}/matomo/tmp/assets" do
111 directory "/opt/matomo-#{version}/matomo/tmp/cache" do
117 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-ASN.mmdb" do
118 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
121 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-City.mmdb" do
122 to "#{geoip_directory}/GeoLite2-City.mmdb"
125 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-Country.mmdb" do
126 to "#{geoip_directory}/GeoLite2-Country.mmdb"
129 mysql_user "piwik@localhost" do
130 password passwords["database"]
133 mysql_database "piwik" do
134 permissions "piwik@localhost" => :all
137 notify_group "matomo-updated"
139 if File.symlink?("/srv/matomo.openstreetmap.org")
140 execute "core:update" do
142 command "/opt/matomo-#{version}/matomo/console core:update --yes"
145 subscribes :run, "notify_group[matomo-updated]"
148 execute "custom-matomo-js:update" do
150 command "/opt/matomo-#{version}/matomo/console custom-matomo-js:update"
153 subscribes :run, "execute[core:update]"
156 execute "/opt/matomo-#{version}/matomo/matomo.js" do
158 command "gzip -k -9 /opt/matomo-#{version}/matomo/matomo.js"
159 cwd "/opt/matomo-#{version}"
162 subscribes :run, "execute[custom-matomo-js:update]"
165 execute "/opt/matomo-#{version}/matomo/piwik.js" do
167 command "gzip -k -9 /opt/matomo-#{version}/matomo/piwik.js"
168 cwd "/opt/matomo-#{version}"
171 subscribes :run, "execute[custom-matomo-js:update]"
175 link "/srv/matomo.openstreetmap.org" do
176 to "/opt/matomo-#{version}/matomo"
177 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
180 ssl_certificate "matomo.openstreetmap.org" do
181 domains ["matomo.openstreetmap.org", "matomo.osm.org",
182 "piwik.openstreetmap.org", "piwik.osm.org"]
183 notifies :reload, "service[apache2]"
186 php_fpm "matomo.openstreetmap.org" do
190 apache_site "matomo.openstreetmap.org" do
191 template "apache.erb"
197 command "/usr/bin/php /srv/matomo.openstreetmap.org/console core:archive --quiet --url=https://matomo.openstreetmap.org/"