]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Add private_devices to some additional services
[chef.git] / cookbooks / otrs / recipes / default.rb
1 #
2 # Cookbook:: otrs
3 # Recipe:: default
4 #
5 # Copyright:: 2012, OpenStreetMap Foundation
6 #
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
10 #
11 #     https://www.apache.org/licenses/LICENSE-2.0
12 #
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.
18 #
19
20 include_recipe "accounts"
21 include_recipe "apache"
22 include_recipe "exim"
23 include_recipe "postgresql"
24 include_recipe "tools"
25
26 passwords = data_bag_item("otrs", "passwords")
27
28 package "libapache2-mod-perl2"
29 package "libapache2-reload-perl"
30
31 package %w[
32   tar
33   bzip2
34   libcrypt-eksblowfish-perl
35   libdatetime-perl
36   libgd-gd2-perl
37   libgd-graph-perl
38   libgd-text-perl
39   libjson-xs-perl
40   libmail-imapclient-perl
41   libmoo-perl
42   libnet-ldap-perl
43   libpdf-api2-perl
44   libsoap-lite-perl
45   libtemplate-perl
46   libyaml-libyaml-perl
47 ]
48
49 apache_module "headers"
50
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] || []
59
60 postgresql_user database_user do
61   cluster database_cluster
62   password database_password
63 end
64
65 postgresql_database database_name do
66   cluster database_cluster
67   owner database_user
68 end
69
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}") }
73 end
74
75 execute "untar-otrs-#{version}" do
76   command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
77   cwd "/opt"
78   user "root"
79   group "root"
80   not_if { ::File.exist?("/opt/otrs-#{version}") }
81 end
82
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")
92
93   line
94 end
95
96 file "/opt/otrs-#{version}/Kernel/Config.pm" do
97   owner user
98   group "www-data"
99   mode "664"
100   content config
101 end
102
103 link "/opt/otrs" do
104   to "/opt/otrs-#{version}"
105 end
106
107 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
108   action :run
109   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
110   user "root"
111   group "root"
112   only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
113 end
114
115 systemd_service "otrs" do
116   description "OTRS Daemon"
117   type "forking"
118   user "otrs"
119   group "otrs"
120   exec_start "/opt/otrs/bin/otrs.Daemon.pl start"
121   private_tmp true
122   private_devices true
123   protect_system "full"
124   protect_home true
125   read_write_paths "/var/log/exim4"
126 end
127
128 service "otrs" do
129   action [:enable, :start]
130   subscribes :restart, "systemd_service[otrs]"
131 end
132
133 ssl_certificate site do
134   domains [site] + site_aliases
135   notifies :reload, "service[apache2]"
136 end
137
138 apache_site site do
139   template "apache.erb"
140   variables :aliases => site_aliases
141 end
142
143 template "/etc/sudoers.d/otrs" do
144   source "sudoers.erb"
145   owner "root"
146   group "root"
147   mode "440"
148 end
149
150 template "/etc/cron.daily/otrs-backup" do
151   source "backup.cron.erb"
152   owner "root"
153   group "root"
154   mode "755"
155 end