]> git.openstreetmap.org Git - chef.git/blob - cookbooks/imagery/resources/site.rb
imagery: trigger nginx reload instead of restart
[chef.git] / cookbooks / imagery / resources / site.rb
1 #
2 # Cookbook Name:: imagery
3 # Resource:: imagery_site
4 #
5 # Copyright 2016, 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 require "yaml"
21
22 default_action :create
23
24 property :name, String
25 property :title, String, :required => true
26 property :aliases, [String, Array], :default => []
27 property :bbox, Array, :required => true
28
29 action :create do
30   directory "/srv/#{name}" do
31     user "root"
32     group "root"
33     mode 0755
34   end
35
36   directory "/srv/imagery/layers/#{name}" do
37     user "root"
38     group "root"
39     mode 0755
40     recursive true
41   end
42
43   directory "/srv/imagery/overlays/#{name}" do
44     user "root"
45     group "root"
46     mode 0755
47     recursive true
48   end
49
50   template "/srv/#{name}/index.html" do
51     source "index.html.erb"
52     user "root"
53     group "root"
54     mode 0644
55     variables :title => title
56   end
57
58   cookbook_file "/srv/#{name}/imagery.css" do
59     source "imagery.css"
60     user "root"
61     group "root"
62     mode 0644
63   end
64
65   layers = Dir.glob("/srv/imagery/layers/#{name}/*.yml").collect do |path|
66     YAML.load(::File.read(path))
67   end
68
69   template "/srv/#{name}/imagery.js" do
70     source "imagery.js.erb"
71     user "root"
72     group "root"
73     mode 0644
74     variables :bbox => bbox, :layers => layers
75   end
76
77   nginx_site name do
78     template "nginx_imagery.conf.erb"
79     directory "/srv/imagery/#{name}"
80     restart_nginx false
81     variables new_resource.to_hash
82   end
83 end
84
85 def after_created
86   notifies :reload, "service[nginx]"
87 end