]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
9644dc6674f1872b741828292966f91eb9e7e1bd
[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 #     http://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::ssl"
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
38 apache_module "headers"
39
40 version = node[:otrs][:version]
41 user = node[:otrs][:user]
42 group = node[:otrs][:group]
43 database_cluster = node[:otrs][:database_cluster]
44 database_name = node[:otrs][:database_name]
45 database_user = node[:otrs][:database_user]
46 database_password = passwords[node[:otrs][:database_password]]
47 site = node[:otrs][:site]
48
49 remote_file "/tmp/otrs-#{version}.tar.bz2" do
50   source "http://ftp.otrs.org/pub/otrs/otrs-#{version}.tar.bz2"
51   not_if { File.exist?("/opt/otrs-#{version}") }
52 end
53
54 execute "untar-otrs-#{version}" do
55   command "tar jxf /tmp/otrs-#{version}.tar.bz2"
56   cwd "/opt"
57   user "root"
58   group "root"
59   not_if { File.exist?("/opt/otrs-#{version}") }
60 end
61
62 config = edit_file "/opt/otrs-#{version}/Kernel/Config.pm.dist" do |line|
63   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
64   line.gsub!(/^( *)\$Self->{DatabaseUser} = 'otrs'/, "\\1$Self->{DatabaseUser} = '#{database_user}'")
65   line.gsub!(/^( *)\$Self->{DatabasePw} = 'some-pass'/, "\\1$Self->{DatabasePw} = '#{database_password}'")
66   line.gsub!(/^( *)\$Self->{Database} = 'otrs'/, "\\1$Self->{Database} = '#{database_name}'")
67   line.gsub!(/^( *\$Self->{DatabaseDSN} = "DBI:mysql:)/, "#\\1")
68   line.gsub!(/^#( *\$Self->{DatabaseDSN} = "DBI:Pg:.*;host=)/, "\\1")
69
70   line
71 end
72
73 file "/opt/otrs-#{version}/Kernel/Config.pm" do
74   owner user
75   group "www-data"
76   mode 0664
77   content config
78 end
79
80 file "/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm" do
81   owner user
82   group "www-data"
83   mode 0664
84   content IO.read("/opt/otrs-#{version}/Kernel/Config/GenericAgent.pm.dist")
85 end
86
87 link "/opt/otrs" do
88   to "/opt/otrs-#{version}"
89 end
90
91 execute "/opt/otrs/bin/otrs.SetPermissions.pl" do
92   action :run
93   command "/opt/otrs/bin/otrs.SetPermissions.pl --otrs-user=#{user} --web-user=www-data --otrs-group=www-data --web-group=www-data /opt/otrs-#{version}"
94   user "root"
95   group "root"
96   not_if { File.stat("/opt/otrs/README.md").uid != Etc.getpwnam("otrs").uid }
97 end
98
99 execute "/opt/otrs/bin/otrs.RebuildConfig.pl" do
100   action :run
101   command "/opt/otrs/bin/otrs.RebuildConfig.pl"
102   user "root"
103   group "root"
104   not_if { File.exist?("/opt/otrs/Kernel/Config/Files/ZZZAAuto.pm") }
105 end
106
107 if node[:postgresql][:clusters][database_cluster]
108   postgresql_user database_user do
109     cluster database_cluster
110     password database_password
111   end
112
113   postgresql_database database_name do
114     cluster database_cluster
115     owner database_user
116   end
117 end
118
119 execute "/opt/otrs/bin/Cron.sh" do
120   action :nothing
121   command "/opt/otrs/bin/Cron.sh restart"
122   user "otrs"
123   group "otrs"
124 end
125
126 Dir.glob("/opt/otrs/var/cron/*.dist") do |distname|
127   name = distname.sub(".dist", "")
128
129   file name do
130     owner "otrs"
131     group "www-data"
132     mode 0664
133     content IO.read(distname)
134     notifies :run, "execute[/opt/otrs/bin/Cron.sh]"
135   end
136 end
137
138 apache_site site do
139   template "apache.erb"
140 end
141
142 template "/etc/sudoers.d/otrs" do
143   source "sudoers.erb"
144   owner "root"
145   group "root"
146   mode 0440
147 end
148
149 template "/etc/cron.daily/otrs-backup" do
150   source "backup.cron.erb"
151   owner "root"
152   group "root"
153   mode 0755
154 end