]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Revert "Go readonly on smaug"
[chef.git] / cookbooks / otrs / recipes / default.rb
1 #
2 # Cookbook Name:: otrs
3 # Recipe:: default
4 #
5 # Copyright 2012, 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 "tools"
21 include_recipe "apache::ssl"
22
23 passwords = data_bag_item("otrs", "passwords")
24
25 package "libapache2-mod-perl2"
26 package "libapache2-reload-perl"
27
28 package "libgd-gd2-perl"
29 package "libgd-graph-perl"
30 package "libgd-text-perl"
31 package "libjson-xs-perl"
32 package "libmail-imapclient-perl"
33 package "libnet-ldap-perl"
34 package "libpdf-api2-perl"
35 package "libsoap-lite-perl"
36
37 apache_module "headers"
38
39 version = node[:otrs][:version]
40 user = node[:otrs][:user]
41 group = node[:otrs][:group]
42 database_cluster = node[:otrs][:database_cluster]
43 database_name = node[:otrs][:database_name]
44 database_user = node[:otrs][:database_user]
45 database_password = passwords[node[:otrs][:database_password]]
46 site = node[:otrs][:site]
47
48 remote_file "/tmp/otrs-#{version}.tar.bz2" do
49   source "http://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
50   not_if { File.exist?("/opt/otrs-#{version}") }
51 end
52
53 execute "untar-otrs-#{version}" do
54   command "tar jxf /tmp/otrs-#{version}.tar.bz2"
55   cwd "/opt"
56   user "root"
57   group "root"
58   not_if { File.exist?("/opt/otrs-#{version}") }
59 end
60
61 file "/opt/otrs-#{version}/Kernel/Config.pm" do
62   owner user
63   group "www-data"
64   mode 0664
65   content_from_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
66     line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
67     line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
68     line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
69     line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
70     line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
71     line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
72
73     line
74   end
75 end
76
77 file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm" do
78   owner user
79   group "www-data"
80   mode 0664
81   content_from_file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm.dist" do |line|
82     line
83   end
84 end
85
86 link "/opt/otrs" do
87   to "/opt/otrs-#{version}"
88 end
89
90 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
91   action :run
92   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-user=www-data --otrs-group=www-data --web-group=www-data /opt/otrs-#{version}"
93   user "root"
94   group "root"
95   not_if { File.stat("/opt/otrs/README").uid != Etc.getpwnam("otrs").uid }
96 end
97
98 execute "/opt/otrs/bin/otrs.RebuildConfig.pl" do
99   action :run
100   command "/opt/otrs/bin/otrs.RebuildConfig.pl"
101   user "root"
102   group "root"
103   not_if { File.exist?("/opt/otrs/Kernel/Config/Files/ZZZAAuto.pm") }
104 end
105
106 if node[:postgresql][:clusters][database_cluster]
107   postgresql_user database_user do
108     cluster database_cluster
109     password database_password
110   end
111
112   postgresql_database database_name do
113     cluster database_cluster
114     owner database_user
115   end
116 end
117
118 execute "/opt/otrs/bin/Cron.sh" do
119   action :nothing
120   command "/opt/otrs/bin/Cron.sh restart"
121   user "otrs"
122   group "otrs"
123 end
124
125 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
126   name = distname.sub(".dist", "")
127
128   file name do
129     owner "otrs"
130     group "www-data"
131     mode 0664
132     content IO.read(distname)
133     notifies :run, resources(:execute => "/opt/otrs/bin/Cron.sh")
134   end
135 end
136
137 apache_site site do
138   template "apache.erb"
139 end
140
141 template "/etc/sudoers.d/otrs" do
142   source "sudoers.erb"
143   owner "root"
144   group "root"
145   mode 0440
146 end
147
148 template "/etc/cron.daily/otrs-backup" do
149   source "backup.cron.erb"
150   owner "root"
151   group "root"
152   mode 0755
153 end