]> git.openstreetmap.org Git - chef.git/blob - cookbooks/piwik/recipes/default.rb
Block access to some piwik internals
[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 directory "/opt/piwik-#{version}" do
43   owner "root"
44   group "root"
45   mode "0755"
46 end
47
48 remote_file "#{Chef::Config[:file_cache_path]}/piwik-#{version}.zip" do
49   source "https://builds.matomo.org/piwik-#{version}.zip"
50   not_if { ::File.exist?("/opt/piwik-#{version}/piwik") }
51 end
52
53 archive_file "#{Chef::Config[:file_cache_path]}/piwik-#{version}.zip" do
54   destination "/opt/piwik-#{version}"
55   overwrite true
56   owner "root"
57   group "root"
58   not_if { ::File.exist?("/opt/piwik-#{version}/piwik") }
59 end
60
61 execute "/opt/piwik-#{version}/piwik/piwik.js" do
62   command "gzip -k -9 /opt/piwik-#{version}/piwik/piwik.js"
63   cwd "/opt/piwik-#{version}"
64   user "root"
65   group "root"
66   not_if { ::File.exist?("/opt/piwik-#{version}/piwik/piwik.js.gz") }
67 end
68
69 directory "/opt/piwik-#{version}/piwik/config" do
70   owner "www-data"
71   group "www-data"
72   mode "0755"
73 end
74
75 template "/opt/piwik-#{version}/piwik/config/config.ini.php" do
76   source "config.erb"
77   owner "root"
78   group "root"
79   mode "0644"
80   variables :passwords => passwords,
81             :directory => "/opt/piwik-#{version}/piwik",
82             :plugins => node[:piwik][:plugins]
83 end
84
85 directory "/opt/piwik-#{version}/piwik/tmp" do
86   owner "www-data"
87   group "www-data"
88   mode "0755"
89 end
90
91 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-ASN.mmdb" do
92   to "/usr/share/GeoIP/GeoLite2-ASN.mmdb"
93 end
94
95 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-City.mmdb" do
96   to "/usr/share/GeoIP/GeoLite2-City.mmdb"
97 end
98
99 link "/opt/piwik-#{version}/piwik/misc/GeoLite2-Country.mmdb" do
100   to "/usr/share/GeoIP/GeoLite2-Country.mmdb"
101 end
102
103 link "/srv/piwik.openstreetmap.org" do
104   to "/opt/piwik-#{version}/piwik"
105   notifies :restart, "service[php#{node[:php][:version]}-fpm]"
106 end
107
108 mysql_user "piwik@localhost" do
109   password passwords["database"]
110 end
111
112 mysql_database "piwik" do
113   permissions "piwik@localhost" => :all
114 end
115
116 ssl_certificate "piwik.openstreetmap.org" do
117   domains ["piwik.openstreetmap.org", "piwik.osm.org"]
118   notifies :reload, "service[apache2]"
119 end
120
121 php_fpm "piwik.openstreetmap.org" do
122   prometheus_port 9253
123 end
124
125 apache_site "piwik.openstreetmap.org" do
126   template "apache.erb"
127 end
128
129 cron_d "piwik" do
130   minute "5"
131   user "www-data"
132   command "/usr/bin/php /srv/piwik.openstreetmap.org/console core:archive --quiet --url=https://piwik.openstreetmap.org/"
133 end