]> git.openstreetmap.org Git - chef.git/blob - cookbooks/chef/recipes/server.rb
5eb30d0b6b5d1417b681eb49c8a307d1011b8de1
[chef.git] / cookbooks / chef / recipes / server.rb
1 #
2 # Cookbook:: chef
3 # Recipe:: server
4 #
5 # Copyright:: 2010, 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 "apache"
21
22 # cache_dir = Chef::Config[:file_cache_path]
23 #
24 # chef_version = node[:chef][:server][:version]
25 # chef_package = "chef-server-core_#{chef_version}-1_amd64.deb"
26 #
27 # Dir.glob("#{cache_dir}/chef-server-core_*.deb").each do |deb|
28 #   next if deb == "#{cache_dir}/#{chef_package}"
29 #
30 #   file deb do
31 #     action :delete
32 #     backup false
33 #   end
34 # end
35 #
36 # remote_file "#{cache_dir}/#{chef_package}" do
37 #   source "https://packages.chef.io/files/stable/chef-server/#{chef_version}/ubuntu/16.04/#{chef_package}"
38 #   owner "root"
39 #   group "root"
40 #   mode 0644
41 #   backup false
42 # end
43 #
44 # dpkg_package "chef-server-core" do
45 #   source "#{cache_dir}/#{chef_package}"
46 #   version "#{chef_version}-1"
47 #   notifies :run, "execute[chef-server-reconfigure]"
48 # end
49
50 template "/etc/opscode/chef-server.rb" do
51   source "server.rb.erb"
52   owner "root"
53   group "root"
54   mode 0o640
55   notifies :run, "execute[chef-server-reconfigure]"
56 end
57
58 execute "chef-server-reconfigure" do
59   action :nothing
60   command "chef-server-ctl reconfigure"
61   user "root"
62   group "root"
63 end
64
65 execute "chef-server-restart" do
66   action :nothing
67   command "chef-server-ctl restart"
68   user "root"
69   group "root"
70 end
71
72 systemd_service "chef-server" do
73   description "Chef server"
74   after "network.target"
75   exec_start "/opt/opscode/embedded/bin/runsvdir-start"
76 end
77
78 service "chef-server" do
79   action [:enable, :start]
80   subscribes :restart, "systemd_service[chef-server]"
81 end
82
83 apache_module "alias"
84 apache_module "proxy_http"
85
86 ssl_certificate "chef.openstreetmap.org" do
87   domains ["chef.openstreetmap.org", "chef.osm.org"]
88   notifies :reload, "service[apache2]"
89   notifies :run, "execute[chef-server-restart]"
90 end
91
92 apache_site "chef.openstreetmap.org" do
93   template "apache.erb"
94 end
95
96 template "/etc/cron.daily/chef-server-backup" do
97   source "server-backup.cron.erb"
98   owner "root"
99   group "root"
100   mode 0o755
101 end
102
103 munin_plugin "chef_status"