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