From: Grant Slater Date: Wed, 14 Aug 2013 20:47:16 +0000 (+0100) Subject: Tile add a very rudimentary client debug script X-Git-Url: https://git.openstreetmap.org./chef.git/commitdiff_plain/3df53dba22117390f55bc350d47ae0e25b19e85d Tile add a very rudimentary client debug script --- diff --git a/cookbooks/tile/recipes/default.rb b/cookbooks/tile/recipes/default.rb index f513088cd..9c219e62d 100644 --- a/cookbooks/tile/recipes/default.rb +++ b/cookbooks/tile/recipes/default.rb @@ -115,6 +115,13 @@ template "/srv/tile.openstreetmap.org/cgi-bin/export" do variables :blocks => blocks end +template "/srv/tile.openstreetmap.org/cgi-bin/debug" do + source "debug.erb" + owner "tile" + group "tile" + mode 0755 +end + template "/etc/cron.hourly/export" do source "export.cron.erb" owner "root" diff --git a/cookbooks/tile/templates/default/debug.erb b/cookbooks/tile/templates/default/debug.erb new file mode 100755 index 000000000..998ed7b0e --- /dev/null +++ b/cookbooks/tile/templates/default/debug.erb @@ -0,0 +1,68 @@ +#!/usr/bin/python -u +# -*- coding: utf-8 -*- + +import cgi +import cgitb +import os +import sys +import resource + +# HTML Debug of errors +cgitb.enable() + +# Limit maximum CPU time +# The Postscript output format can sometimes take hours +resource.setrlimit(resource.RLIMIT_CPU,(180,180)) + +# Limit memory usage +# Some odd requests can cause extreme memory usage +resource.setrlimit(resource.RLIMIT_AS,(4000000000, 4000000000)) + +# Routine to output HTTP headers +def output_headers(content_type, filename = "", length = 0): + print "Cache-Control: no-cache, no-store, must-revalidate')" + print "Pragma: no-cache" + print "Expires: 0" + print "Content-Type: %s" % content_type + if filename: + print "Content-Disposition: attachment; filename=\"%s\"" % filename + if length: + print "Content-Length: %d" % length + print "" + +# Routine to report an error +def output_error(message): + output_headers("text/html") + print "" + print "" + print "Error" + print "" + print "" + print "

Error

" + print "

%s

" % message + print "" + print "" + +# Make sure we have a user agent +if not os.environ.has_key('HTTP_USER_AGENT'): + os.environ['HTTP_USER_AGENT'] = 'NONE' + +# Get the load average +loadavg = float(open("/proc/loadavg").readline().split(" ")[0]) + +output_headers("text/html") +print "" +print "" +print "tile.openstreetmap.org debug" +print "" +print "" +print "

tile.openstreetmap.org debug

" +print "

Server Stats

" +print "

Load Average:%s

" % loadavg +print "

Browser Request Headers

" +print "

" +for param in os.environ.keys(): + print "%20s: %s
" % (param, os.environ[param]) +print "

" +print "" +print ""