Cleanup temporary files from the export CGI script
authorTom Hughes <tom@compton.nu>
Wed, 7 Aug 2013 08:03:31 +0000 (09:03 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 7 Aug 2013 08:03:31 +0000 (09:03 +0100)
cookbooks/tile/recipes/default.rb
cookbooks/tile/templates/default/export.cron.erb [new file with mode: 0644]
cookbooks/tile/templates/default/export.erb [changed mode: 0755->0644]

index 2e17ac58b2f0ede959e6114853206b9b9f1962f7..bb8b347edf506933cb167f9610e1f17f68ed5cbd 100644 (file)
@@ -121,6 +121,13 @@ template "/srv/tile.openstreetmap.org/cgi-bin/export" do
   variables :blocks => blocks
 end
 
   variables :blocks => blocks
 end
 
+template "/etc/cron.hourly/export" do
+  source "export.cron.erb"
+  owner "root"
+  group "root"
+  mode 0755
+end
+
 directory "/srv/tile.openstreetmap.org/data" do
   owner "tile"
   group "tile"
 directory "/srv/tile.openstreetmap.org/data" do
   owner "tile"
   group "tile"
diff --git a/cookbooks/tile/templates/default/export.cron.erb b/cookbooks/tile/templates/default/export.cron.erb
new file mode 100644 (file)
index 0000000..da82854
--- /dev/null
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+# Removes stale tmp files from the export tab
+exec find /tmp -name 'export??????' -mmin +60 -delete
old mode 100755 (executable)
new mode 100644 (file)
index ae37fee..d178df4
@@ -129,21 +129,21 @@ else:
         output_headers("image/jpeg", "map.jpg", len(jpeg))
         sys.stdout.write(jpeg)
       elif form.getvalue("format") == "svg":
         output_headers("image/jpeg", "map.jpg", len(jpeg))
         sys.stdout.write(jpeg)
       elif form.getvalue("format") == "svg":
-        file = tempfile.NamedTemporaryFile()
+        file = tempfile.NamedTemporaryFile(prefix = "export")
         surface = cairo.SVGSurface(file.name, map.width, map.height)
         mapnik.render(map, surface)
         surface.finish()
         output_headers("image/svg+xml", "map.svg", file_size(file))
         output_file(file)
       elif form.getvalue("format") == "pdf":
         surface = cairo.SVGSurface(file.name, map.width, map.height)
         mapnik.render(map, surface)
         surface.finish()
         output_headers("image/svg+xml", "map.svg", file_size(file))
         output_file(file)
       elif form.getvalue("format") == "pdf":
-        file = tempfile.NamedTemporaryFile()
+        file = tempfile.NamedTemporaryFile(prefix = "export")
         surface = cairo.PDFSurface(file.name, map.width, map.height)
         mapnik.render(map, surface)
         surface.finish()
         output_headers("application/pdf", "map.pdf", file_size(file))
         output_file(file)
       elif form.getvalue("format") == "ps":
         surface = cairo.PDFSurface(file.name, map.width, map.height)
         mapnik.render(map, surface)
         surface.finish()
         output_headers("application/pdf", "map.pdf", file_size(file))
         output_file(file)
       elif form.getvalue("format") == "ps":
-        file = tempfile.NamedTemporaryFile()
+        file = tempfile.NamedTemporaryFile(prefix = "export")
         surface = cairo.PSSurface(file.name, map.width, map.height)
         mapnik.render(map, surface)
         surface.finish()
         surface = cairo.PSSurface(file.name, map.width, map.height)
         mapnik.render(map, surface)
         surface.finish()