]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Modernise mod_perl installation
[chef.git] / cookbooks / otrs / recipes / default.rb
1 #
2 # Cookbook:: 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 "accounts"
21 include_recipe "apache"
22 include_recipe "exim"
23 include_recipe "postgresql"
24 include_recipe "tools"
25
26 passwords = data_bag_item("otrs", "passwords")
27
28 package %w[
29   tar
30   bzip2
31   libapache-dbi-perl
32   libapache2-reload-perl
33   libarchive-zip-perl
34   libauthen-ntlm-perl
35   libauthen-sasl-perl
36   libcrypt-eksblowfish-perl
37   libcss-minifier-xs-perl
38   libdatetime-perl
39   libdbd-mysql-perl
40   libencode-hanextra-perl
41   libexcel-writer-xlsx-perl
42   libgd-gd2-perl
43   libgd-graph-perl
44   libgd-text-perl
45   libhtml-parser-perl
46   libio-socket-ssl-perl
47   libjavascript-minifier-xs-perl
48   libjson-perl
49   libjson-xs-perl
50   liblocale-codes-perl
51   libmail-imapclient-perl
52   libmoo-perl
53   libnet-dns-perl
54   libnet-ldap-perl
55   libpdf-api2-perl
56   libsisimai-perl
57   libsoap-lite-perl
58   libspreadsheet-xlsx-perl
59   libtemplate-perl
60   libtext-csv-xs-perl
61   libtext-diff-perl
62   libtimedate-perl
63   libxml-libxml-perl
64   libxml-libxml-simple-perl
65   libxml-libxslt-perl
66   libxml-parser-perl
67   libxml-simple-perl
68   libyaml-libyaml-perl
69   libyaml-perl
70 ]
71
72 apache_module "perl" do
73   package "libapache2-mod-perl2"
74 end
75
76 apache_module "deflate"
77 apache_module "headers"
78 apache_module "rewrite"
79
80 version = node[:otrs][:version]
81 user = node[:otrs][:user]
82 database_cluster = node[:otrs][:database_cluster]
83 database_name = node[:otrs][:database_name]
84 database_user = node[:otrs][:database_user]
85 database_password = passwords[node[:otrs][:database_password]]
86 site = node[:otrs][:site]
87 site_aliases = node[:otrs][:site_aliases] || []
88
89 postgresql_user database_user do
90   cluster database_cluster
91   password database_password
92 end
93
94 postgresql_database database_name do
95   cluster database_cluster
96   owner database_user
97 end
98
99 remote_file "#{Chef::Config[:file_cache_path]}/znuny-#{version}.tar.bz2" do
100   source "https://download.znuny.org/releases/znuny-#{version}.tar.bz2"
101   not_if { ::File.exist?("/opt/znuny-#{version}") }
102 end
103
104 execute "untar-znuny-#{version}" do
105   command "tar jxf #{Chef::Config[:file_cache_path]}/znuny-#{version}.tar.bz2"
106   cwd "/opt"
107   user "root"
108   group "root"
109   not_if { ::File.exist?("/opt/znuny-#{version}") }
110 end
111
112 config = edit_file "/opt/znuny-#{version}/Kernel/Config.pm.dist" do |line|
113   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
114   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
115   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
116   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
117   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
118   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
119   line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
120   line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
121
122   line
123 end
124
125 file "/opt/znuny-#{version}/Kernel/Config.pm" do
126   owner user
127   group "www-data"
128   mode "664"
129   content config
130   notifies :restart, "service[otrs]"
131 end
132
133 execute "/opt/znuny-#{version}/bin/otrs.SetPermissions.pl" do
134   action :nothing
135   command "/opt/znuny-#{version}/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/znuny-#{version}"
136   user "root"
137   group "root"
138   subscribes :run, "execute[untar-znuny-#{version}]"
139 end
140
141 link "/opt/otrs" do
142   to "/opt/znuny-#{version}"
143 end
144
145 systemd_service "otrs" do
146   description "OTRS Daemon"
147   type "forking"
148   user "otrs"
149   group "otrs"
150   exec_start "/opt/otrs/bin/otrs.Daemon.pl start"
151   private_tmp true
152   protect_system "strict"
153   protect_home true
154   read_write_paths ["/opt/znuny-#{version}/var", "/var/log/exim4", "/var/spool/exim4"]
155 end
156
157 service "otrs" do
158   action [:enable, :start]
159   subscribes :restart, "link[/opt/otrs]"
160   subscribes :restart, "systemd_service[otrs]"
161 end
162
163 ssl_certificate site do
164   domains [site] + site_aliases
165   notifies :reload, "service[apache2]"
166 end
167
168 apache_site site do
169   template "apache.erb"
170   variables :aliases => site_aliases
171 end
172
173 template "/etc/cron.daily/otrs-backup" do
174   source "backup.cron.erb"
175   owner "root"
176   group "root"
177   mode "755"
178 end