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 # http://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::ssl"
24 passwords = data_bag_item("otrs", "passwords")
26 package "libapache2-mod-perl2"
27 package "libapache2-reload-perl"
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"
40 apache_module "headers"
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]
50 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
51 source "http://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
52 not_if { File.exist?("/opt/otrs-#{version}") }
55 execute "untar-otrs-#{version}" do
56 command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
60 not_if { File.exist?("/opt/otrs-#{version}") }
63 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
64 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
65 line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
66 line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
67 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
68 line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
69 line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
70 line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
75 file "/opt/otrs-#{version}/Kernel/Config.pm" do
82 generic_agent = edit_file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm.dist" do |line|
86 file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm" do
94 to "/opt/otrs-#{version}"
97 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
99 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}"
102 only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
105 execute "/opt/otrs/bin/otrs.RebuildConfig.pl" do
107 command "/opt/otrs/bin/otrs.RebuildConfig.pl"
110 not_if { File.exist?("/opt/otrs/Kernel/Config/Files/ZZZAAuto.pm") }
113 if node[:postgresql][:clusters][database_cluster]
114 postgresql_user database_user do
115 cluster database_cluster
116 password database_password
119 postgresql_database database_name do
120 cluster database_cluster
125 execute "/opt/otrs/bin/Cron.sh" do
127 command "/opt/otrs/bin/Cron.sh restart"
132 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
133 name = distname.sub(".dist", "")
139 content IO.read(distname)
140 notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
145 template "apache.erb"
148 template "/etc/sudoers.d/otrs" do
155 template "/etc/cron.daily/otrs-backup" do
156 source "backup.cron.erb"