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