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 "accounts"
21 include_recipe "apache"
23 include_recipe "postgresql"
24 include_recipe "tools"
26 passwords = data_bag_item("otrs", "passwords")
28 package "libapache2-mod-perl2"
29 package "libapache2-reload-perl"
34 libcrypt-eksblowfish-perl
40 libmail-imapclient-perl
49 apache_module "headers"
51 version = node[:otrs][:version]
52 user = node[:otrs][:user]
53 database_cluster = node[:otrs][:database_cluster]
54 database_name = node[:otrs][:database_name]
55 database_user = node[:otrs][:database_user]
56 database_password = passwords[node[:otrs][:database_password]]
57 site = node[:otrs][:site]
58 site_aliases = node[:otrs][:site_aliases] || []
60 postgresql_user database_user do
61 cluster database_cluster
62 password database_password
65 postgresql_database database_name do
66 cluster database_cluster
70 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
71 source "https://download.znuny.org/releases/otrs-#{version}.tar.bz2"
72 not_if { ::File.exist?("/opt/otrs-#{version}") }
75 execute "untar-otrs-#{version}" do
76 command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
80 not_if { ::File.exist?("/opt/otrs-#{version}") }
83 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
84 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
85 line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
86 line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
87 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
88 line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
89 line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
90 line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
91 line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
96 file "/opt/otrs-#{version}/Kernel/Config.pm" do
104 to "/opt/otrs-#{version}"
107 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
109 command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
112 only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
115 systemd_service "otrs" do
116 description "OTRS Daemon"
120 exec_start "/opt/otrs/bin/otrs.Daemon.pl start"
122 protect_system "full"
124 read_write_paths "/var/log/exim4"
128 action [:enable, :start]
129 subscribes :restart, "systemd_service[otrs]"
132 ssl_certificate site do
133 domains [site] + site_aliases
134 notifies :reload, "service[apache2]"
138 template "apache.erb"
139 variables :aliases => site_aliases
142 template "/etc/sudoers.d/otrs" do
149 template "/etc/cron.daily/otrs-backup" do
150 source "backup.cron.erb"