2 # Cookbook Name:: imagery
3 # Resource:: imagery_layer
5 # Copyright 2016, OpenStreetMap Foundation
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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
22 default_action :create
24 property :layer, String, :name_property => true
25 property :site, String, :required => true
26 property :source, String, :required => true
27 property :root_layer, [TrueClass, FalseClass], :default => false
28 property :text, String
29 property :copyright, String, :default => "Copyright"
30 property :projection, String, :default => "EPSG:3857"
31 property :palette, String
32 property :extent, String
33 property :background_colour, String
34 property :resample, String, :default => "average"
35 property :imagemode, String
36 property :extension, String, :default => "png"
37 property :max_zoom, Fixnum, :default => 23
38 property :url_aliases, [String, Array], :default => []
39 property :revision, Fixnum, :default => 1
40 property :overlay, [TrueClass, FalseClass], :default => false
44 file "create layer yaml definition" do
49 path "/srv/imagery/overlays/#{site}/#{layer}.yml"
51 path "/srv/imagery/layers/#{site}/#{layer}.yml"
53 content YAML.dump(:name => layer,
54 :url => "http://#{site}/layer/#{layer}/{z}/{x}/{y}.#{extension}",
55 :attribution => copyright,
59 file "remove old layer yaml" do
61 path "/srv/imagery/layers/#{site}/#{layer}.yml" # remove layer if overlay
63 path "/srv/imagery/overlays/#{site}/#{layer}.yml" # remove overlay if layer
68 template "/srv/imagery/mapserver/layer-#{layer}.map" do
70 source "mapserver.map.erb"
74 variables new_resource.to_hash
77 systemd_service "mapserv-fcgi-#{layer}" do
78 description "Map server for #{layer} layer"
80 environment "MS_MAPFILE" => "/srv/imagery/mapserver/layer-#{layer}.map",
81 "MS_MAP_PATTERN" => "^/srv/imagery/mapserver/"
84 exec_start_pre "/bin/rm -f /run/mapserver-fastcgi/layer-#{layer}.socket"
85 exec_start "/usr/bin/spawn-fcgi -s /run/mapserver-fastcgi/layer-#{layer}.socket -M 0666 -P /run/mapserver-fastcgi/layer-#{layer}.pid -- /usr/bin/multiwatch -f 4 --signal=TERM -- /usr/lib/cgi-bin/mapserv"
86 pid_file "/run/mapserver-fastcgi/layer-#{layer}.pid"
91 service "mapserv-fcgi-#{layer}" do
92 action [:enable, :start]
93 subscribes :restart, "template[/srv/imagery/mapserver/layer-#{layer}.map]"
94 subscribes :restart, "systemd_service[mapserv-fcgi]"
97 directory "/srv/imagery/nginx/#{site}" do
104 template "/srv/imagery/nginx/#{site}/layer-#{layer}.conf" do
106 source "nginx_imagery_layer_fragment.conf.erb"
110 variables new_resource.to_hash
115 service "mapserv-fcgi-layer-#{layer}" do
116 action [:stop, :disable]
119 file "/srv/imagery/mapserver/layer-#{layer}.map" do
123 systemd_service "mapserv-fcgi-#{layer}" do
127 file "/srv/imagery/nginx/#{site}/layer-#{layer}.conf" do
133 notifies :create, "imagery_site[#{site}]"
134 notifies :restart, "service[nginx]"