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