]> git.openstreetmap.org Git - chef.git/blob - cookbooks/piwik/recipes/default.rb
f377fe0603d57a57a5d1e37b90ce0a7454113b40
[chef.git] / cookbooks / piwik / recipes / default.rb
1 #
2 # Cookbook Name:: 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 "mysql"
22
23 passwords = data_bag_item("piwik", "passwords")
24
25 package "php"
26 package "php-cli"
27 package "php-curl"
28 package "php-mbstring"
29 package "php-mysql"
30 package "php-gd"
31 package "php-xml"
32 package "php-apcu"
33
34 package "geoip-database-contrib"
35
36 apache_module "php7.2"
37 apache_module "geoip"
38
39 version = node[:piwik][:version]
40
41 directory "/opt/piwik-#{version}" do
42   owner "root"
43   group "root"
44   mode "0755"
45 end
46
47 remote_file "#{Chef::Config[:file_cache_path]}/piwik-#{version}.zip" do
48   source "https://builds.matomo.org/piwik-#{version}.zip"
49   not_if { File.exist?("/opt/piwik-#{version}/piwik") }
50 end
51
52 execute "unzip-piwik-#{version}" do
53   command "unzip -q #{Chef::Config[:file_cache_path]}/piwik-#{version}.zip"
54   cwd "/opt/piwik-#{version}"
55   user "root"
56   group "root"
57   not_if { File.exist?("/opt/piwik-#{version}/piwik") }
58 end
59
60 directory "/opt/piwik-#{version}/piwik/config" do
61   owner "www-data"
62   group "www-data"
63   mode "0755"
64 end
65
66 template "/opt/piwik-#{version}/piwik/config/config.ini.php" do
67   source "config.erb"
68   owner "root"
69   group "root"
70   mode "0644"
71   variables :passwords => passwords,
72             :directory => "/opt/piwik-#{version}/piwik",
73             :plugins => node[:piwik][:plugins]
74 end
75
76 directory "/opt/piwik-#{version}/piwik/tmp" do
77   owner "www-data"
78   group "www-data"
79   mode "0755"
80 end
81
82 link "/srv/piwik.openstreetmap.org" do
83   to "/opt/piwik-#{version}/piwik"
84   notifies :restart, "service[apache2]"
85 end
86
87 mysql_user "piwik@localhost" do
88   password passwords["database"]
89 end
90
91 mysql_database "piwik" do
92   permissions "piwik@localhost" => :all
93 end
94
95 ssl_certificate "piwik.openstreetmap.org" do
96   domains ["piwik.openstreetmap.org", "piwik.osm.org"]
97   notifies :reload, "service[apache2]"
98 end
99
100 apache_site "piwik.openstreetmap.org" do
101   template "apache.erb"
102 end
103
104 template "/etc/cron.d/piwiki" do
105   source "cron.erb"
106   owner "root"
107   group "root"
108   mode "0644"
109 end