From: Grant Slater Date: Sun, 17 Jan 2016 23:41:42 +0000 (+0000) Subject: Imagery add site + layer resources X-Git-Url: https://git.openstreetmap.org/chef.git/commitdiff_plain/7426769ee7efed7e0559a58bb5e9bfd9f43d6c2a Imagery add site + layer resources --- diff --git a/cookbooks/imagery/recipes/default.rb b/cookbooks/imagery/recipes/default.rb index e12487875..7c3d186aa 100644 --- a/cookbooks/imagery/recipes/default.rb +++ b/cookbooks/imagery/recipes/default.rb @@ -47,6 +47,13 @@ directory "/var/run/mapserver-fastcgi" do mode 0755 end +directory "/srv/imagery/mapserver" do + owner "root" + group "root" + mode 0755 + recursive true +end + directory "/srv/imagery/common" do owner "root" group "root" diff --git a/cookbooks/imagery/resources/layer.rb b/cookbooks/imagery/resources/layer.rb new file mode 100644 index 000000000..9356a77a4 --- /dev/null +++ b/cookbooks/imagery/resources/layer.rb @@ -0,0 +1,62 @@ +# +# Cookbook Name:: imagery +# Resource:: imagery_layer +# +# Copyright 2016, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default_action :create + +property :name, String +property :site, String, :required => true +property :source, String, :required => true +property :text, String +property :copyright, String, :default => "Copyright" +property :projection, String, :default => "EPSG:3857" +property :palette, String +property :extent, String +property :background, String +property :resample, String, :default => "average" +property :imagemode, String +property :extension, String +property :max_zoom, Fixnum, :default => 23 + +action :create do + template "/srv/imagery/mapserver/layer-#{name}.map" do + cookbook "imagery" + source "mapserver.map.erb" + owner "root" + group "root" + mode 0644 + variables new_resource.to_hash + end + + template "/etc/init/mapserv-fgi-layer-#{name}.conf" do + cookbook "imagery" + source "mapserv_fcgi.conf.erb" + owner "root" + group "root" + mode 0644 + variables new_resource.to_hash + end + + service "mapserv-fgi-layer-#{name}.conf" do + provider Chef::Provider::Service::Upstart + action [:enable, :start] + supports :status => true, :restart => true, :reload => false + subscribes :restart, "template[/srv/imagery/mapserver/layer-#{name}.map]" + subscribes :restart, "template[/etc/init/mapserv-fgi-layer-#{name}.conf]" + end +end diff --git a/cookbooks/imagery/resources/site.rb b/cookbooks/imagery/resources/site.rb new file mode 100644 index 000000000..76f6ca13d --- /dev/null +++ b/cookbooks/imagery/resources/site.rb @@ -0,0 +1,37 @@ +# +# Cookbook Name:: imagery +# Resource:: imagery_site +# +# Copyright 2016, OpenStreetMap Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +default_action :create + +property :name, String + +action :create do + + directory "/srv/imagery/#{name}" do + owner "root" + group "root" + mode 0755 + end + + nginx_site "#{name}" do + template "nginx_imagery.conf.erb" + directory "/srv/imagery/#{name}" + variables new_resource.to_hash + end +end diff --git a/cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb b/cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb new file mode 100644 index 000000000..9f6e25093 --- /dev/null +++ b/cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb @@ -0,0 +1,29 @@ +# DO NOT EDIT - This file is being maintained by Chef + +description "starts mapserver in daemon mode for fastcgi" + +start on (net-device-up + and local-filesystems + and runlevel [2345]) +stop on runlevel [!2345] + +respawn + +setuid imagery +setgid imagery + +limit nofile 16384 16384 + +# https://trac.osgeo.org/mapserver/wiki/EnvironmentVariables +env MS_MAPFILE="/srv/imagery/mapserver/layer-<%= @name %>.map" +env MS_MAP_PATTERN="^/srv/imagery/mapserver/" +env MS_ERRORFILE="/tmp/mapserver-layer-<%= @name %>.log" +env MS_DEBUGLEVEL="5" + +script + exec /usr/bin/spawn-fcgi \ + -n \ + -s /var/run/mapserver-fastcgi/layer-<%= @name %>.socket \ + -M 0666 \ + -f /usr/lib/cgi-bin/mapserv +end script diff --git a/cookbooks/imagery/templates/default/mapserver.map.erb b/cookbooks/imagery/templates/default/mapserver.map.erb new file mode 100644 index 000000000..b3f93c726 --- /dev/null +++ b/cookbooks/imagery/templates/default/mapserver.map.erb @@ -0,0 +1,23 @@ +# DO NOT EDIT - This file is being maintained by Chef +MAP + NAME "map-<%= @name %>" + STATUS ON + SIZE 256 256 + UNITS METERS + IMAGETYPE png + PROJECTION + "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs +nadgrids=/srv/imagery/common/ostn02-ntv2-data/OSTN02_NTv2.gsb" + END + + LAYER + NAME "<%= @name %>" + DATA "<%= @source %>" + PROJECTION + "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +datum=OSGB36 +units=m +no_defs +nadgrids=/srv/imagery/common/ostn02-ntv2-data/OSTN02_NTv2.gsb" + END + STATUS ON + TYPE RASTER + PROCESSING "RESAMPLE=AVERAGE" + PROCESSING "CLOSE_CONNECTION=DEFER" + END # layer +END diff --git a/cookbooks/imagery/templates/default/nginx_imagery.conf.erb b/cookbooks/imagery/templates/default/nginx_imagery.conf.erb new file mode 100644 index 000000000..5b3b91eb4 --- /dev/null +++ b/cookbooks/imagery/templates/default/nginx_imagery.conf.erb @@ -0,0 +1,8 @@ +server { + listen 80; + server_name <%= @name %>; + + #FIXME WIP + #Needs to include or iterate through layers with rewrite + fastcgi + #Git checkout of web? +}