]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Use packages libosmium and protozero on taginfo server.
[chef.git] / cookbooks / otrs / recipes / default.rb
1 #
2 # Cookbook Name:: 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 "tools"
21 include_recipe "postgresql"
22 include_recipe "apache"
23
24 passwords = data_bag_item("otrs", "passwords")
25
26 package "libapache2-mod-perl2"
27 package "libapache2-reload-perl"
28
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"
39 package "libtemplate-perl"
40
41 apache_module "headers"
42
43 version = node[:otrs][:version]
44 user = node[:otrs][:user]
45 database_cluster = node[:otrs][:database_cluster]
46 database_name = node[:otrs][:database_name]
47 database_user = node[:otrs][:database_user]
48 database_password = passwords[node[:otrs][:database_password]]
49 site = node[:otrs][:site]
50 site_aliases = node[:otrs][:site_aliases] || []
51
52 postgresql_user database_user do
53   cluster database_cluster
54   password database_password
55 end
56
57 postgresql_database database_name do
58   cluster database_cluster
59   owner database_user
60 end
61
62 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
63   source "https://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
64   not_if { File.exist?("/opt/otrs-#{version}") }
65 end
66
67 execute "untar-otrs-#{version}" do
68   command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
69   cwd "/opt"
70   user "root"
71   group "root"
72   not_if { File.exist?("/opt/otrs-#{version}") }
73 end
74
75 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
76   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
77   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
78   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
79   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
80   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
81   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
82   line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
83
84   line
85 end
86
87 file "/opt/otrs-#{version}/Kernel/Config.pm" do
88   owner user
89   group "www-data"
90   mode 0o664
91   content config
92 end
93
94 link "/opt/otrs" do
95   to "/opt/otrs-#{version}"
96 end
97
98 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
99   action :run
100   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
101   user "root"
102   group "root"
103   only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
104 end
105
106 execute "/opt/otrs/bin/otrs.RebuildConfig.pl" do
107   action :run
108   command "/opt/otrs/bin/otrs.RebuildConfig.pl"
109   user "root"
110   group "root"
111   not_if { File.exist?("/opt/otrs/Kernel/Config/Files/ZZZAAuto.pm") }
112 end
113
114 execute "/opt/otrs/bin/Cron.sh" do
115   action :nothing
116   command "/opt/otrs/bin/Cron.sh restart"
117   user "otrs"
118   group "otrs"
119 end
120
121 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
122   name = distname.sub(".dist", "")
123
124   file name do
125     owner "otrs"
126     group "www-data"
127     mode 0o664
128     content IO.read(distname)
129     notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
130   end
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 0o440
148 end
149
150 template "/etc/cron.daily/otrs-backup" do
151   source "backup.cron.erb"
152   owner "root"
153   group "root"
154   mode 0o755
155 end