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("piwik", "passwords")
37 apache_module "expires"
38 apache_module "rewrite"
40 version = node[:piwik][:version]
42 geoip_directory = node[:geoipupdate][:directory]
44 directory "/opt/piwik-#{version}" do
50 remote_file "#{Chef::Config[:file_cache_path]}/piwik-#{version}.zip" do
51 source "https://builds.matomo.org/piwik-#{version}.zip"
52 not_if { ::File.exist?("/opt/piwik-#{version}/piwik") }
55 archive_file "#{Chef::Config[:file_cache_path]}/piwik-#{version}.zip" do
56 destination "/opt/piwik-#{version}"
60 not_if { ::File.exist?("/opt/piwik-#{version}/piwik") }
63 node[:piwik][:plugins].each do |plugin_name, plugin_version|
64 next if plugin_version.nil?
66 remote_file "#{Chef::Config[:file_cache_path]}/piwik-#{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]}/piwik-#{plugin_name}-#{plugin_version}.zip" do
72 destination "/opt/piwik-#{version}/piwik/plugins"
76 subscribes :extract, "remote_file[#{Chef::Config[:file_cache_path]}/piwik-#{plugin_name}-#{plugin_version}.zip]", :immediately
80 execute "/opt/piwik-#{version}/piwik/piwik.js" do
81 command "gzip -k -9 /opt/piwik-#{version}/piwik/piwik.js"
82 cwd "/opt/piwik-#{version}"
85 not_if { ::File.exist?("/opt/piwik-#{version}/piwik/piwik.js.gz") }
88 directory "/opt/piwik-#{version}/piwik/config" do
94 template "/opt/piwik-#{version}/piwik/config/config.ini.php" do
99 variables :passwords => passwords,
100 :directory => "/opt/piwik-#{version}/piwik",
101 :plugins => node[:piwik][:plugins].keys.sort
104 directory "/opt/piwik-#{version}/piwik/tmp" do
110 directory "/opt/piwik-#{version}/piwik/tmp/assets" do
116 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-ASN.mmdb" do
117 to "#{geoip_directory}/GeoLite2-ASN.mmdb"
120 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-City.mmdb" do
121 to "#{geoip_directory}/GeoLite2-City.mmdb"
124 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-Country.mmdb" do
125 to "#{geoip_directory}/GeoLite2-Country.mmdb"
128 link "/srv/piwik.openstreetmap.org" do
129 to "/opt/piwik-#{version}/piwik"
130 notifies :restart, "service[php#{node[:php][:version]}-fpm]"
133 mysql_user "piwik@localhost" do
134 password passwords["database"]
137 mysql_database "piwik" do
138 permissions "piwik@localhost" => :all
141 ssl_certificate "piwik.openstreetmap.org" do
142 domains ["piwik.openstreetmap.org", "piwik.osm.org"]
143 notifies :reload, "service[apache2]"
146 php_fpm "piwik.openstreetmap.org" do
150 apache_site "piwik.openstreetmap.org" do
151 template "apache.erb"
157 command "/usr/bin/php /srv/piwik.openstreetmap.org/console core:archive --quiet --url=https://piwik.openstreetmap.org/"