imagery: move service from layer to site
authorGrant Slater <git@firefishy.com>
Wed, 5 Sep 2018 21:35:26 +0000 (22:35 +0100)
committerGrant Slater <git@firefishy.com>
Wed, 5 Sep 2018 21:35:26 +0000 (22:35 +0100)
cookbooks/imagery/resources/layer.rb
cookbooks/imagery/resources/site.rb
cookbooks/imagery/templates/default/nginx_imagery_layer_fragment.conf.erb

index 6741a6d..7f6fc53 100644 (file)
@@ -61,38 +61,17 @@ action :create do
     group "root"
     mode 0o644
     variables new_resource.to_hash
+    notify :restart, "service[mapserv-fcgi-#{new_resource.site}]"
   end
 
-  systemd_service "mapserv-fcgi-#{new_resource.layer}" do
-    description "Map server for #{new_resource.layer} layer"
-    environment "MS_MAPFILE" => "/srv/imagery/mapserver/layer-#{new_resource.layer}.map",
-                "MS_MAP_PATTERN" => "^/srv/imagery/mapserver/",
-                "MS_DEBUGLEVEL" => "0",
-                "MS_ERRORFILE" => "stderr",
-                "GDAL_CACHEMAX" => "64"
-    limit_nofile 16384
-    memory_high "512M"
-    memory_max "1G"
-    user "imagery"
-    group "imagery"
-    exec_start_pre "/bin/rm -f /run/mapserver-fastcgi/layer-#{new_resource.layer}.socket"
-    exec_start "/usr/bin/spawn-fcgi -n -b 128 -s /run/mapserver-fastcgi/layer-#{new_resource.layer}.socket -M 0666 -P /run/mapserver-fastcgi/layer-#{new_resource.layer}.pid -- /usr/bin/multiwatch -f 2 --signal=TERM -- /usr/lib/cgi-bin/mapserv"
-    private_tmp true
-    private_devices true
-    private_network true
-    protect_system "full"
-    protect_home true
-    no_new_privileges true
-    restart "always"
-    pid_file "/run/mapserver-fastcgi/layer-#{new_resource.layer}.pid"
+  # Disable legacy service
+  service "mapserv-fcgi-#{new_resource.layer}" do
+    action [:stop, :disable]
   end
 
-  service "mapserv-fcgi-#{new_resource.layer}" do
-    provider Chef::Provider::Service::Systemd
-    action [:enable, :start]
-    supports :status => true, :restart => true, :reload => false
-    subscribes :restart, "template[/srv/imagery/mapserver/layer-#{new_resource.layer}.map]"
-    subscribes :restart, "systemd_service[mapserv-fcgi-#{new_resource.layer}]"
+  # Remove legacy service
+  systemd_service "mapserv-fcgi-#{new_resource.layer}" do
+    action :delete
   end
 
   directory "/srv/imagery/nginx/#{new_resource.site}" do
index 9519b63..6ae5166 100644 (file)
@@ -91,6 +91,36 @@ action :create do
   base_domains = [new_resource.site] + Array(new_resource.aliases)
   tile_domains = base_domains.flat_map { |d| [d, "a.#{d}", "b.#{d}", "c.#{d}"] }
 
+  systemd_service "mapserv-fcgi-#{new_resource.site}" do
+    description "Map server for #{new_resource.site} layer"
+    environment "MS_MAP_PATTERN" => "^/srv/imagery/mapserver/",
+                "MS_DEBUGLEVEL" => "0",
+                "MS_ERRORFILE" => "stderr",
+                "GDAL_CACHEMAX" => "256"
+    limit_nofile 16384
+    memory_high "512M"
+    memory_max "1G"
+    user "imagery"
+    group "imagery"
+    exec_start_pre "/bin/rm -f /run/mapserver-fastcgi/layer-#{new_resource.site}.socket"
+    exec_start "/usr/bin/spawn-fcgi -n -b 128 -s /run/mapserver-fastcgi/layer-#{new_resource.site}.socket -M 0666 -P /run/mapserver-fastcgi/layer-#{new_resource.site}.pid -- /usr/bin/multiwatch -f 2 --signal=TERM -- /usr/lib/cgi-bin/mapserv"
+    private_tmp true
+    private_devices true
+    private_network true
+    protect_system "full"
+    protect_home true
+    no_new_privileges true
+    restart "always"
+    pid_file "/run/mapserver-fastcgi/layer-#{new_resource.site}.pid"
+  end
+
+  service "mapserv-fcgi-#{new_resource.site}" do
+    provider Chef::Provider::Service::Systemd
+    action [:enable, :start]
+    supports :status => true, :restart => true, :reload => false
+    subscribes :restart, "systemd_service[mapserv-fcgi-#{new_resource.site}]"
+  end
+
   ssl_certificate new_resource.site do
     domains tile_domains
   end
@@ -103,6 +133,20 @@ action :create do
   end
 end
 
+action :delete do
+  service "mapserv-fcgi-#{new_resource.site}" do
+    action [:stop, :disable]
+  end
+
+  systemd_service "mapserv-fcgi-#{new_resource.site}" do
+    action :delete
+  end
+
+  nginx_site new_resource.site do
+    action :delete
+  end
+end
+
 def after_created
   notifies :reload, "service[nginx]"
 end
index e527f12..5ef9a15 100644 (file)
@@ -3,7 +3,7 @@
 location ~* "^/layer/<%= @layer %>/(\d+)/(\d+)/(\d+)\.(png|jpg|jpeg)$" {
   # Override QUERY_STRING to force mapserver query parameters
   fastcgi_param QUERY_STRING "map=/srv/imagery/mapserver/layer-<%= @layer %>.map&mode=tile&layers=<%= @layer %>&tilemode=gmap&tile=$2+$3+$1";
-  fastcgi_pass "unix:/var/run/mapserver-fastcgi/layer-<%= @layer %>.socket";
+  fastcgi_pass "unix:/var/run/mapserver-fastcgi/layer-<%= @site %>.socket";
   fastcgi_buffers 8 64k;
   include fastcgi_params;
   fastcgi_param REQUEST_METHOD "GET";