5 # Copyright:: 2012, OpenStreetMap Foundation
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
11 # https://www.apache.org/licenses/LICENSE-2.0
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.
20 include_recipe "tools"
21 include_recipe "postgresql"
22 include_recipe "apache"
24 passwords = data_bag_item("otrs", "passwords")
26 package "libapache2-mod-perl2"
27 package "libapache2-reload-perl"
30 libcrypt-eksblowfish-perl
36 libmail-imapclient-perl
44 apache_module "headers"
46 version = node[:otrs][:version]
47 user = node[:otrs][:user]
48 database_cluster = node[:otrs][:database_cluster]
49 database_name = node[:otrs][:database_name]
50 database_user = node[:otrs][:database_user]
51 database_password = passwords[node[:otrs][:database_password]]
52 site = node[:otrs][:site]
53 site_aliases = node[:otrs][:site_aliases] || []
55 postgresql_user database_user do
56 cluster database_cluster
57 password database_password
60 postgresql_database database_name do
61 cluster database_cluster
65 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
66 source "https://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
67 not_if { ::File.exist?("/opt/otrs-#{version}") }
70 execute "untar-otrs-#{version}" do
71 command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
75 not_if { ::File.exist?("/opt/otrs-#{version}") }
78 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
79 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
80 line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
81 line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
82 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
83 line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
84 line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
85 line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
86 line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
91 file "/opt/otrs-#{version}/Kernel/Config.pm" do
99 to "/opt/otrs-#{version}"
102 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
104 command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
107 only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
110 execute "/opt/otrs/bin/Cron.sh" do
112 command "/opt/otrs/bin/Cron.sh restart"
117 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
118 name = distname.sub(".dist", "")
124 content IO.read(distname)
125 notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
129 ssl_certificate site do
130 domains [site] + site_aliases
131 notifies :reload, "service[apache2]"
135 template "apache.erb"
136 variables :aliases => site_aliases
139 template "/etc/sudoers.d/otrs" do
146 template "/etc/cron.daily/otrs-backup" do
147 source "backup.cron.erb"