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"
 
  24 passwords = data_bag_item("piwik", "passwords")
 
  38 apache_module "expires"
 
  39 apache_module "php7.2"
 
  40 apache_module "rewrite"
 
  42 version = node[:piwik][:version]
 
  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 execute "unzip-piwik-#{version}" do
 
  56   command "unzip -q #{Chef::Config[:file_cache_path]}/piwik-#{version}.zip"
 
  57   cwd "/opt/piwik-#{version}"
 
  60   not_if { ::File.exist?("/opt/piwik-#{version}/piwik") }
 
  63 execute "/opt/piwik-#{version}/piwik/piwik.js" do
 
  64   command "gzip -k -9 /opt/piwik-#{version}/piwik/piwik.js"
 
  65   cwd "/opt/piwik-#{version}"
 
  68   not_if { ::File.exist?("/opt/piwik-#{version}/piwik/piwik.js.gz") }
 
  71 directory "/opt/piwik-#{version}/piwik/config" do
 
  77 template "/opt/piwik-#{version}/piwik/config/config.ini.php" do
 
  82   variables :passwords => passwords,
 
  83             :directory => "/opt/piwik-#{version}/piwik",
 
  84             :plugins => node[:piwik][:plugins]
 
  87 directory "/opt/piwik-#{version}/piwik/tmp" do
 
  93 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-ASN.mmdb" do
 
  94   to "/usr/share/GeoIP/GeoLite2-ASN.mmdb"
 
  97 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-City.mmdb" do
 
  98   to "/usr/share/GeoIP/GeoLite2-City.mmdb"
 
 101 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-Country.mmdb" do
 
 102   to "/usr/share/GeoIP/GeoLite2-Country.mmdb"
 
 105 link "/srv/piwik.openstreetmap.org" do
 
 106   to "/opt/piwik-#{version}/piwik"
 
 107   notifies :restart, "service[apache2]"
 
 110 mysql_user "piwik@localhost" do
 
 111   password passwords["database"]
 
 114 mysql_database "piwik" do
 
 115   permissions "piwik@localhost" => :all
 
 118 ssl_certificate "piwik.openstreetmap.org" do
 
 119   domains ["piwik.openstreetmap.org", "piwik.osm.org"]
 
 120   notifies :reload, "service[apache2]"
 
 123 apache_site "piwik.openstreetmap.org" do
 
 124   template "apache.erb"
 
 127 template "/etc/cron.d/piwiki" do