]> git.openstreetmap.org Git - chef.git/commitdiff
Imagery add site + layer resources
authorGrant Slater <git@firefishy.com>
Sun, 17 Jan 2016 23:41:42 +0000 (23:41 +0000)
committerGrant Slater <git@firefishy.com>
Sun, 31 Jan 2016 16:47:14 +0000 (16:47 +0000)
cookbooks/imagery/recipes/default.rb
cookbooks/imagery/resources/layer.rb [new file with mode: 0644]
cookbooks/imagery/resources/site.rb [new file with mode: 0644]
cookbooks/imagery/templates/default/mapserv_fcgi.conf.erb [new file with mode: 0644]
cookbooks/imagery/templates/default/mapserver.map.erb [new file with mode: 0644]
cookbooks/imagery/templates/default/nginx_imagery.conf.erb [new file with mode: 0644]

index e1248787525870f117759ca4cea2c6a2facbf1e9..7c3d186aaa642b744fd5385478235fe361444d32 100644 (file)
@@ -47,6 +47,13 @@ directory "/var/run/mapserver-fastcgi" do
   mode 0755
 end
 
   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"
 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 (file)
index 0000000..9356a77
--- /dev/null
@@ -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 (file)
index 0000000..76f6ca1
--- /dev/null
@@ -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 (file)
index 0000000..9f6e250
--- /dev/null
@@ -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 (file)
index 0000000..b3f93c7
--- /dev/null
@@ -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 (file)
index 0000000..5b3b91e
--- /dev/null
@@ -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?
+}