]> git.openstreetmap.org Git - chef.git/blob - cookbooks/otrs/recipes/default.rb
7aae679537ceceb291f3df9157853891de21a487
[chef.git] / cookbooks / otrs / recipes / default.rb
1 #
2 # Cookbook:: otrs
3 # Recipe:: default
4 #
5 # Copyright:: 2024, 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 apache_module "perl" do
29   package "libapache2-mod-perl2"
30 end
31
32 apache_module "deflate"
33 apache_module "headers"
34 apache_module "rewrite"
35
36 database_cluster = node[:otrs][:database_cluster]
37 database_name = node[:otrs][:database_name]
38 database_user = node[:otrs][:database_user]
39 database_password = passwords[node[:otrs][:database_password]]
40 site = node[:otrs][:site]
41 site_aliases = node[:otrs][:site_aliases] || []
42
43 postgresql_user database_user do
44   cluster database_cluster
45   password database_password
46 end
47
48 postgresql_database database_name do
49   cluster database_cluster
50   owner database_user
51 end
52
53 package "dbconfig-common"
54
55 template "/etc/dbconfig-common/otrs2.conf" do
56   source "dbconfig.config.erb"
57   owner "root"
58   group "root"
59   mode "600"
60   variables :database_name => database_name,
61             :database_user => database_user,
62             :database_password => database_password,
63             :database_cluster => database_cluster
64 end
65
66 # Ensure the OTRS package in backports has a priority preference.
67 apt_preference "otrs2" do
68   pin "release o=Debian Backports"
69   pin_priority "600"
70 end
71
72 apt_package "otrs2"
73
74 # Ensure debconf is repopulated on a dbconfig change
75 execute "dpkg-reconfigure-otrs2" do
76   action :nothing
77   command "dpkg-reconfigure -fnoninteractive otrs2"
78   subscribes :run, "template[/etc/dbconfig-common/otrs2.conf]"
79 end
80
81 # Disable deb otrs2 apache config
82 apache_conf "otrs2" do
83   action :disable
84 end
85
86 # Disable deb otrs2 cron job
87 file "/etc/cron.d/otrs2" do
88   action :delete
89   manage_symlink_source true
90 end
91
92 systemd_service "otrs" do
93   description "OTRS Daemon"
94   type "forking"
95   user "otrs"
96   group "www-data"
97   exec_start_pre "-/usr/share/otrs/bin/otrs.Daemon.pl stop" # Stop if race with deb cron
98   exec_start "/usr/share/otrs/bin/otrs.Daemon.pl start"
99   private_tmp true
100   protect_system "strict"
101   protect_home "read-only"
102   runtime_directory "otrs"
103   runtime_directory_mode 0o770
104   runtime_directory_preserve true
105   read_write_paths ["/var/lib/otrs", "/run/otrs", "/var/log/exim4", "/var/spool/exim4"]
106 end
107
108 service "otrs" do
109   action [:enable, :start]
110   subscribes :restart, "apt_package[otrs2]"
111   subscribes :restart, "systemd_service[otrs]"
112 end
113
114 ssl_certificate site do
115   domains [site] + site_aliases
116   notifies :reload, "service[apache2]"
117 end
118
119 apache_site site do
120   template "apache.erb"
121   variables :aliases => site_aliases
122 end
123
124 template "/etc/cron.daily/otrs-backup" do
125   source "backup.cron.erb"
126   owner "root"
127   group "root"
128   mode "755"
129 end