]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Fix OTRS test failures
[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   libcrypt-eksblowfish-perl
33   libdatetime-perl
34   libgd-gd2-perl
35   libgd-graph-perl
36   libgd-text-perl
37   libjson-xs-perl
38   libmail-imapclient-perl
39   libmoo-perl
40   libnet-ldap-perl
41   libpdf-api2-perl
42   libsoap-lite-perl
43   libtemplate-perl
44   libyaml-libyaml-perl
45 ]
46
47 apache_module "headers"
48
49 version = node[:otrs][:version]
50 user = node[:otrs][:user]
51 database_cluster = node[:otrs][:database_cluster]
52 database_name = node[:otrs][:database_name]
53 database_user = node[:otrs][:database_user]
54 database_password = passwords[node[:otrs][:database_password]]
55 site = node[:otrs][:site]
56 site_aliases = node[:otrs][:site_aliases] || []
57
58 postgresql_user database_user do
59   cluster database_cluster
60   password database_password
61 end
62
63 postgresql_database database_name do
64   cluster database_cluster
65   owner database_user
66 end
67
68 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
69   source "https://download.znuny.org/releases/otrs-#{version}.tar.bz2"
70   not_if { ::File.exist?("/opt/otrs-#{version}") }
71 end
72
73 execute "untar-otrs-#{version}" do
74   command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
75   cwd "/opt"
76   user "root"
77   group "root"
78   not_if { ::File.exist?("/opt/otrs-#{version}") }
79 end
80
81 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
82   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
83   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
84   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
85   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
86   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
87   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
88   line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
89   line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
90
91   line
92 end
93
94 file "/opt/otrs-#{version}/Kernel/Config.pm" do
95   owner user
96   group "www-data"
97   mode "664"
98   content config
99 end
100
101 link "/opt/otrs" do
102   to "/opt/otrs-#{version}"
103 end
104
105 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
106   action :run
107   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
108   user "root"
109   group "root"
110   only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
111 end
112
113 systemd_service "otrs" do
114   description "OTRS Daemon"
115   type "forking"
116   user "otrs"
117   group "otrs"
118   exec_start "/opt/otrs/bin/otrs.Daemon.pl start"
119   private_tmp true
120   protect_system "full"
121   protect_home true
122   read_write_paths "/var/log/exim4"
123 end
124
125 service "otrs" do
126   action [:enable, :start]
127   subscribes :restart, "systemd_service[otrs]"
128 end
129
130 ssl_certificate site do
131   domains [site] + site_aliases
132   notifies :reload, "service[apache2]"
133 end
134
135 apache_site site do
136   template "apache.erb"
137   variables :aliases => site_aliases
138 end
139
140 template "/etc/sudoers.d/otrs" do
141   source "sudoers.erb"
142   owner "root"
143   group "root"
144   mode "440"
145 end
146
147 template "/etc/cron.daily/otrs-backup" do
148   source "backup.cron.erb"
149   owner "root"
150   group "root"
151   mode "755"
152 end