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"
38 libcrypt-eksblowfish-perl
39 libcss-minifier-xs-perl
42 libencode-hanextra-perl
43 libexcel-writer-xlsx-perl
49 libjavascript-minifier-xs-perl
53 libmail-imapclient-perl
60 libspreadsheet-xlsx-perl
66 libxml-libxml-simple-perl
75 apache_module "rewrite"
76 apache_module "headers"
77 apache_module "deflate"
79 version = node[:otrs][:version]
80 user = node[:otrs][:user]
81 database_cluster = node[:otrs][:database_cluster]
82 database_name = node[:otrs][:database_name]
83 database_user = node[:otrs][:database_user]
84 database_password = passwords[node[:otrs][:database_password]]
85 site = node[:otrs][:site]
86 site_aliases = node[:otrs][:site_aliases] || []
88 postgresql_user database_user do
89 cluster database_cluster
90 password database_password
93 postgresql_database database_name do
94 cluster database_cluster
98 remote_file "#{Chef::Config[:file_cache_path]}/znuny-#{version}.tar.bz2" do
99 source "https://download.znuny.org/releases/znuny-#{version}.tar.bz2"
100 not_if { ::File.exist?("/opt/znuny-#{version}") }
103 execute "untar-znuny-#{version}" do
104 command "tar jxf #{Chef::Config[:file_cache_path]}/znuny-#{version}.tar.bz2"
108 not_if { ::File.exist?("/opt/znuny-#{version}") }
111 config = edit_file "/opt/znuny-#{version}/Kernel/Config.pm.dist" do |line|
112 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
113 line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
114 line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
115 line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
116 line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
117 line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
118 line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
119 line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
124 file "/opt/znuny-#{version}/Kernel/Config.pm" do
129 notifies :restart, "service[otrs]"
132 execute "/opt/znuny-#{version}/bin/otrs.SetPermissions.pl" do
134 command "/opt/znuny-#{version}/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/znuny-#{version}"
137 subscribes :run, "execute[untar-znuny-#{version}]"
141 to "/opt/znuny-#{version}"
144 systemd_service "otrs" do
145 description "OTRS Daemon"
149 exec_start "/opt/otrs/bin/otrs.Daemon.pl start"
151 protect_system "strict"
153 read_write_paths ["/opt/znuny-#{version}/var", "/var/log/exim4", "/var/spool/exim4"]
157 action [:enable, :start]
158 subscribes :restart, "link[/opt/otrs]"
159 subscribes :restart, "systemd_service[otrs]"
162 ssl_certificate site do
163 domains [site] + site_aliases
164 notifies :reload, "service[apache2]"
168 template "apache.erb"
169 variables :aliases => site_aliases
172 template "/etc/cron.daily/otrs-backup" do
173 source "backup.cron.erb"