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")
32 libapache2-reload-perl
36 libcrypt-eksblowfish-perl
37 libcss-minifier-xs-perl
40 libencode-hanextra-perl
41 libexcel-writer-xlsx-perl
47 libjavascript-minifier-xs-perl
51 libmail-imapclient-perl
58 libspreadsheet-xlsx-perl
64 libxml-libxml-simple-perl
72 apache_module "perl" do
73 package "libapache2-mod-perl2"
76 apache_module "deflate"
77 apache_module "headers"
78 apache_module "rewrite"
80 version = node[:otrs][:version]
81 user = node[:otrs][:user]
82 database_cluster = node[:otrs][:database_cluster]
83 database_name = node[:otrs][:database_name]
84 database_user = node[:otrs][:database_user]
85 database_password = passwords[node[:otrs][:database_password]]
86 site = node[:otrs][:site]
87 site_aliases = node[:otrs][:site_aliases] || []
89 postgresql_user database_user do
90 cluster database_cluster
91 password database_password
94 postgresql_database database_name do
95 cluster database_cluster
99 remote_file "#{Chef::Config[:file_cache_path]}/znuny-#{version}.tar.bz2" do
100 source "https://download.znuny.org/releases/znuny-#{version}.tar.bz2"
101 not_if { ::File.exist?("/opt/znuny-#{version}") }
104 execute "untar-znuny-#{version}" do
105 command "tar jxf #{Chef::Config[:file_cache_path]}/znuny-#{version}.tar.bz2"
109 not_if { ::File.exist?("/opt/znuny-#{version}") }
112 config = edit_file "/opt/znuny-#{version}/Kernel/Config.pm.dist" do |line|
113 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
114 line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
115 line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
116 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
117 line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
118 line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
119 line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
120 line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
125 file "/opt/znuny-#{version}/Kernel/Config.pm" do
130 notifies :restart, "service[otrs]"
133 execute "/opt/znuny-#{version}/bin/otrs.SetPermissions.pl" do
135 command "/opt/znuny-#{version}/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/znuny-#{version}"
138 subscribes :run, "execute[untar-znuny-#{version}]"
142 to "/opt/znuny-#{version}"
145 systemd_service "otrs" do
146 description "OTRS Daemon"
150 exec_start "/opt/otrs/bin/otrs.Daemon.pl start"
152 protect_system "strict"
154 read_write_paths ["/opt/znuny-#{version}/var", "/var/log/exim4", "/var/spool/exim4"]
158 action [:enable, :start]
159 subscribes :restart, "link[/opt/otrs]"
160 subscribes :restart, "systemd_service[otrs]"
163 ssl_certificate site do
164 domains [site] + site_aliases
165 notifies :reload, "service[apache2]"
169 template "apache.erb"
170 variables :aliases => site_aliases
173 template "/etc/cron.daily/otrs-backup" do
174 source "backup.cron.erb"