]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Merge what remains of apache::ssl into apache::default
[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 "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
40 apache_module "headers"
41
42 version = node[:otrs][:version]
43 user = node[:otrs][:user]
44 database_cluster = node[:otrs][:database_cluster]
45 database_name = node[:otrs][:database_name]
46 database_user = node[:otrs][:database_user]
47 database_password = passwords[node[:otrs][:database_password]]
48 site = node[:otrs][:site]
49
50 postgresql_user database_user do
51   cluster database_cluster
52   password database_password
53 end
54
55 postgresql_database database_name do
56   cluster database_cluster
57   owner database_user
58 end
59
60 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
61   source "http://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
62   not_if { File.exist?("/opt/otrs-#{version}") }
63 end
64
65 execute "untar-otrs-#{version}" do
66   command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
67   cwd "/opt"
68   user "root"
69   group "root"
70   not_if { File.exist?("/opt/otrs-#{version}") }
71 end
72
73 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
74   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
75   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
76   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
77   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
78   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
79   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
80   line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
81
82   line
83 end
84
85 file "/opt/otrs-#{version}/Kernel/Config.pm" do
86   owner user
87   group "www-data"
88   mode 0o664
89   content config
90 end
91
92 generic_agent = edit_file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm.dist" do |line|
93   line
94 end
95
96 file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm" do
97   owner user
98   group "www-data"
99   mode 0o664
100   content generic_agent
101 end
102
103 link "/opt/otrs" do
104   to "/opt/otrs-#{version}"
105 end
106
107 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
108   action :run
109   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}"
110   user "root"
111   group "root"
112   only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
113 end
114
115 execute "/opt/otrs/bin/otrs.RebuildConfig.pl" do
116   action :run
117   command "/opt/otrs/bin/otrs.RebuildConfig.pl"
118   user "root"
119   group "root"
120   not_if { File.exist?("/opt/otrs/Kernel/Config/Files/ZZZAAuto.pm") }
121 end
122
123 execute "/opt/otrs/bin/Cron.sh" do
124   action :nothing
125   command "/opt/otrs/bin/Cron.sh restart"
126   user "otrs"
127   group "otrs"
128 end
129
130 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
131   name = distname.sub(".dist", "")
132
133   file name do
134     owner "otrs"
135     group "www-data"
136     mode 0o664
137     content IO.read(distname)
138     notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
139   end
140 end
141
142 ssl_certificate site do
143   domains site
144   notifies :reload, "service[apache2]"
145 end
146
147 apache_site site do
148   template "apache.erb"
149 end
150
151 template "/etc/sudoers.d/otrs" do
152   source "sudoers.erb"
153   owner "root"
154   group "root"
155   mode 0o440
156 end
157
158 template "/etc/cron.daily/otrs-backup" do
159   source "backup.cron.erb"
160   owner "root"
161   group "root"
162   mode 0o755
163 end