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"
52 not_if { ::File.exist?("/opt/matomo-#{version}/matomo") }
55 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{version}.zip" do
56 destination "/opt/matomo-#{version}"
60 not_if { ::File.exist?("/opt/matomo-#{version}/matomo") }
63 node[:matomo][:plugins].each do |plugin_name, plugin_version|
64 next if plugin_version.nil?
66 remote_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
67 source "https://plugins.matomo.org/api/2.0/plugins/#{plugin_name}/download/#{plugin_version}"
70 archive_file "#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip" do
72 destination "/opt/matomo-#{version}/matomo/plugins"
76 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/matomo-#{plugin_name}-#{plugin_version}.zip]", :immediately
80 execute "/opt/matomo-#{version}/matomo/matomo.js" do
81 command "gzip -k -9 /opt/matomo-#{version}/matomo/matomo.js"
82 cwd "/opt/matomo-#{version}"
85 not_if { ::File.exist?("/opt/matomo-#{version}/matomo/matomo.js.gz") }
88 execute "/opt/matomo-#{version}/matomo/piwik.js" do
89 command "gzip -k -9 /opt/matomo-#{version}/matomo/piwik.js"
90 cwd "/opt/matomo-#{version}"
93 not_if { ::File.exist?("/opt/matomo-#{version}/matomo/piwik.js.gz") }
96 directory "/opt/matomo-#{version}/matomo/config" do
102 template "/opt/matomo-#{version}/matomo/config/config.ini.php" do
107 variables :passwords => passwords,
108 :directory => "/opt/matomo-#{version}/matomo",
109 :plugins => node[:matomo][:plugins].keys.sort
112 directory "/opt/matomo-#{version}/matomo/tmp" do
118 directory "/opt/matomo-#{version}/matomo/tmp/assets" do
124 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-ASN.mmdb" do
125 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
128 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-City.mmdb" do
129 to "#{geoip_directory}/GeoLite2-City.mmdb"
132 link "/opt/matomo-#{version}/matomo/misc/GeoLite2-Country.mmdb" do
133 to "#{geoip_directory}/GeoLite2-Country.mmdb"
136 link "/srv/matomo.openstreetmap.org" do
137 to "/opt/matomo-#{version}/matomo"
138 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
141 mysql_user "piwik@localhost" do
142 password passwords["database"]
145 mysql_database "piwik" do
146 permissions "piwik@localhost" => :all
149 ssl_certificate "matomo.openstreetmap.org" do
150 domains ["matomo.openstreetmap.org", "matomo.osm.org",
151 "piwik.openstreetmap.org", "piwik.osm.org"]
152 notifies :reload, "service[apache2]"
155 php_fpm "matomo.openstreetmap.org" do
159 apache_site "matomo.openstreetmap.org" do
160 template "apache.erb"
166 command "/usr/bin/php /srv/matomo.openstreetmap.org/console core:archive --quiet --url=https://matomo.openstreetmap.org/"