]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
Use strings for file modes
[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 "postgresql"
23 include_recipe "tools"
24
25 passwords = data_bag_item("otrs", "passwords")
26
27 package "libapache2-mod-perl2"
28 package "libapache2-reload-perl"
29
30 package %w[
31   libcrypt-eksblowfish-perl
32   libdatetime-perl
33   libgd-gd2-perl
34   libgd-graph-perl
35   libgd-text-perl
36   libjson-xs-perl
37   libmail-imapclient-perl
38   libnet-ldap-perl
39   libpdf-api2-perl
40   libsoap-lite-perl
41   libtemplate-perl
42   libyaml-libyaml-perl
43 ]
44
45 apache_module "headers"
46
47 version = node[:otrs][:version]
48 user = node[:otrs][:user]
49 database_cluster = node[:otrs][:database_cluster]
50 database_name = node[:otrs][:database_name]
51 database_user = node[:otrs][:database_user]
52 database_password = passwords[node[:otrs][:database_password]]
53 site = node[:otrs][:site]
54 site_aliases = node[:otrs][:site_aliases] || []
55
56 postgresql_user database_user do
57   cluster database_cluster
58   password database_password
59 end
60
61 postgresql_database database_name do
62   cluster database_cluster
63   owner database_user
64 end
65
66 remote_file "#{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2" do
67   source "https://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
68   not_if { ::File.exist?("/opt/otrs-#{version}") }
69 end
70
71 execute "untar-otrs-#{version}" do
72   command "tar jxf #{Chef::Config[:file_cache_path]}/otrs-#{version}.tar.bz2"
73   cwd "/opt"
74   user "root"
75   group "root"
76   not_if { ::File.exist?("/opt/otrs-#{version}") }
77 end
78
79 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
80   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
81   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
82   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
83   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
84   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
85   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
86   line.gsub!(/^( *)# (\$Self->{CheckMXRecord} = 0)/, "\\1\\2")
87   line.gsub!(/^( *)# \$Self->{SessionUseCookie} = 0/, "\\1$Self->{SessionCheckRemoteIP} = 0")
88
89   line
90 end
91
92 file "/opt/otrs-#{version}/Kernel/Config.pm" do
93   owner user
94   group "www-data"
95   mode "664"
96   content config
97 end
98
99 link "/opt/otrs" do
100   to "/opt/otrs-#{version}"
101 end
102
103 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
104   action :run
105   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-group=www-data /opt/otrs-#{version}"
106   user "root"
107   group "root"
108   only_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
109 end
110
111 execute "/opt/otrs/bin/Cron.sh" do
112   action :nothing
113   command "/opt/otrs/bin/Cron.sh restart"
114   user "otrs"
115   group "otrs"
116 end
117
118 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
119   name = distname.sub(".dist", "")
120
121   file name do
122     owner "otrs"
123     group "www-data"
124     mode "664"
125     content IO.read(distname)
126     notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
127   end
128 end
129
130 ssl_certificate site do
131   domains [site] + site_aliases
132   notifies :reload, "service[apache2]"
133 end
134
135 apache_site site do
136   template "apache.erb"
137   variables :aliases => site_aliases
138 end
139
140 template "/etc/sudoers.d/otrs" do
141   source "sudoers.erb"
142   owner "root"
143   group "root"
144   mode "440"
145 end
146
147 template "/etc/cron.daily/otrs-backup" do
148   source "backup.cron.erb"
149   owner "root"
150   group "root"
151   mode "755"
152 end