]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Update OTRS to 4.0.29
[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 #     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 "tools"
21 include_recipe "postgresql"
22 include_recipe "apache"
23
24 passwords = data_bag_item("otrs", "passwords")
25
26 package "libapache2-mod-perl2"
27 package "libapache2-reload-perl"
28
29 package "libgd-gd2-perl"
30 package "libgd-graph-perl"
31 package "libgd-text-perl"
32 package "libjson-xs-perl"
33 package "libmail-imapclient-perl"
34 package "libnet-ldap-perl"
35 package "libpdf-api2-perl"
36 package "libsoap-lite-perl"
37 package "libyaml-libyaml-perl"
38 package "libcrypt-eksblowfish-perl"
39 package "libtemplate-perl"
40
41 apache_module "headers"
42
43 version = node[:otrs][:version]
44 user = node[:otrs][:user]
45 database_cluster = node[:otrs][:database_cluster]
46 database_name = node[:otrs][:database_name]
47 database_user = node[:otrs][:database_user]
48 database_password = passwords[node[:otrs][:database_password]]
49 site = node[:otrs][:site]
50
51 old_installation = begin
52                      File.readlink("/opt/otrs")
53                    rescue StandardError
54                      nil
55                    end
56
57 postgresql_user database_user do
58   cluster database_cluster
59   password database_password
60 end
61
62 postgresql_database database_name do
63   cluster database_cluster
64   owner database_user
65 end
66
67 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
68   source "https://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
69   not_if { File.exist?("/opt/otrs-#{version}") }
70 end
71
72 execute "untar-otrs-#{version}" do
73   command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
74   cwd "/opt"
75   user "root"
76   group "root"
77   not_if { File.exist?("/opt/otrs-#{version}") }
78 end
79
80 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
81   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
82   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
83   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
84   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
85   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
86   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
87   line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
88
89   line
90 end
91
92 file "/opt/otrs-#{version}/Kernel/Config.pm" do
93   owner user
94   group "www-data"
95   mode 0o664
96   content config
97 end
98
99 generic_agent = edit_file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm.dist" do |line|
100   line
101 end
102
103 file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm" do
104   owner user
105   group "www-data"
106   mode 0o664
107   content generic_agent
108 end
109
110 link "/opt/otrs-#{version}/Kernel/Config/Files/ZZZAuto.pm" do
111   to "#{old_installation}/Kernel/Config/Files/ZZZAuto.pm"
112   link_type :hard
113 end
114
115 link "/opt/otrs-#{version}/var/log/TicketCounter.log" do
116   to "#{old_installation}/var/log/TicketCounter.log"
117   link_type :hard
118 end
119
120 link "/opt/otrs" do
121   to "/opt/otrs-#{version}"
122 end
123
124 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
125   action :run
126   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
127   user "root"
128   group "root"
129   only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
130 end
131
132 execute "/opt/otrs/bin/otrs.RebuildConfig.pl" do
133   action :run
134   command "/opt/otrs/bin/otrs.RebuildConfig.pl"
135   user "root"
136   group "root"
137   not_if { File.exist?("/opt/otrs/Kernel/Config/Files/ZZZAAuto.pm") }
138 end
139
140 execute "/opt/otrs/bin/Cron.sh" do
141   action :nothing
142   command "/opt/otrs/bin/Cron.sh restart"
143   user "otrs"
144   group "otrs"
145 end
146
147 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
148   name = distname.sub(".dist", "")
149
150   file name do
151     owner "otrs"
152     group "www-data"
153     mode 0o664
154     content IO.read(distname)
155     notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
156   end
157 end
158
159 ssl_certificate site do
160   domains site
161   notifies :reload, "service[apache2]"
162 end
163
164 apache_site site do
165   template "apache.erb"
166 end
167
168 template "/etc/sudoers.d/otrs" do
169   source "sudoers.erb"
170   owner "root"
171   group "root"
172   mode 0o440
173 end
174
175 template "/etc/cron.daily/otrs-backup" do
176   source "backup.cron.erb"
177   owner "root"
178   group "root"
179   mode 0o755
180 end