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