]> git.openstreetmap.org Git - chef.git/blob - cookbooks/piwik/recipes/default.rb
Set mapnik version to 3.1 everywhere as it's what we are using
[chef.git] / cookbooks / piwik / recipes / default.rb
1 #
2 # Cookbook:: piwik
3 # Recipe:: default
4 #
5 # Copyright:: 2011, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "apache"
21 include_recipe "geoipupdate"
22 include_recipe "mysql"
23 include_recipe "php::fpm"
24
25 passwords = data_bag_item("piwik", "passwords")
26
27 package %w[
28   php-cli
29   php-curl
30   php-mbstring
31   php-mysql
32   php-gd
33   php-xml
34   php-apcu
35 ]
36
37 apache_module "expires"
38 apache_module "rewrite"
39
40 version = node[:piwik][:version]
41
42 geoip_directory = node[:geoipupdate][:directory]
43
44 directory "/opt/piwik-#{version}" do
45   owner "root"
46   group "root"
47   mode "0755"
48 end
49
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") }
53 end
54
55 archive_file "#{Chef::Config[:file_cache_path]}/piwik-#{version}.zip" do
56   destination "/opt/piwik-#{version}"
57   overwrite true
58   owner "root"
59   group "root"
60   not_if { ::File.exist?("/opt/piwik-#{version}/piwik") }
61 end
62
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}"
66   user "root"
67   group "root"
68   not_if { ::File.exist?("/opt/piwik-#{version}/piwik/piwik.js.gz") }
69 end
70
71 directory "/opt/piwik-#{version}/piwik/config" do
72   owner "www-data"
73   group "www-data"
74   mode "0755"
75 end
76
77 template "/opt/piwik-#{version}/piwik/config/config.ini.php" do
78   source "config.erb"
79   owner "root"
80   group "root"
81   mode "0644"
82   variables :passwords => passwords,
83             :directory => "/opt/piwik-#{version}/piwik",
84             :plugins => node[:piwik][:plugins]
85 end
86
87 directory "/opt/piwik-#{version}/piwik/tmp" do
88   owner "www-data"
89   group "www-data"
90   mode "0755"
91 end
92
93 directory "/opt/piwik-#{version}/piwik/tmp/assets" do
94   owner "www-data"
95   group "mysql"
96   mode "0750"
97 end
98
99 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-ASN.mmdb" do
100   to "#{geoip_directory}/GeoLite2-ASN.mmdb"
101 end
102
103 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-City.mmdb" do
104   to "#{geoip_directory}/GeoLite2-City.mmdb"
105 end
106
107 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-Country.mmdb" do
108   to "#{geoip_directory}/GeoLite2-Country.mmdb"
109 end
110
111 link "/srv/piwik.openstreetmap.org" do
112   to "/opt/piwik-#{version}/piwik"
113   notifies :restart, "service[php#{node[:php][:version]}-fpm]"
114 end
115
116 mysql_user "piwik@localhost" do
117   password passwords["database"]
118 end
119
120 mysql_database "piwik" do
121   permissions "piwik@localhost" => :all
122 end
123
124 ssl_certificate "piwik.openstreetmap.org" do
125   domains ["piwik.openstreetmap.org", "piwik.osm.org"]
126   notifies :reload, "service[apache2]"
127 end
128
129 php_fpm "piwik.openstreetmap.org" do
130   prometheus_port 9253
131 end
132
133 apache_site "piwik.openstreetmap.org" do
134   template "apache.erb"
135 end
136
137 cron_d "piwik" do
138   minute "5"
139   user "www-data"
140   command "/usr/bin/php /srv/piwik.openstreetmap.org/console core:archive --quiet --url=https://piwik.openstreetmap.org/"
141 end