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