[Tilecache] Running Standalone under WSGI with tilecache_http_server.py

manel.clos at ajgirona.cat manel.clos at ajgirona.cat
Wed Oct 27 04:14:31 EDT 2010

Hi David,

You can use mod_wsgi on Apache. I'm happily using it with no problems.

I don't know why at this point there is no tilecache.wsgi in the tilecache distribution. I would really like others to comment about it, and also about the script/configuration below.

Here is an example mod_wsgi configuration for TileCache
   # WMSC - TileCache
    WSGIDaemonProcess coloma-wmsc user=umat group=www-data processes=1 threads=25 display-name=coloma-wmsc inactivity-timeout=600
    <Directory /home/umat/dades/wmsc/>
        WSGIProcessGroup coloma-wmsc

    WSGIScriptAliasMatch ^/wmsc/([^/]+) /home/umat/dades/wmsc/$1/tilecache.wsgi

This configuration allows multiple instances of TileCache.

And here is a simple version of tilecache.wsgi:
import os, sys
base_path, tail = os.path.split(__file__)

tilecachepath = base_path
from TileCache.Service import Service, wsgiHandler

cfgfiles = (os.path.join(tilecachepath, "tilecache.cfg"))

theService = {}
def wsgiApp (environ, start_response):
    global theService

    cfgs = cfgfiles

    if not theService:
        theService = Service.load(cfgs)
    return wsgiHandler(environ, start_response, theService)

application = wsgiApp

This version will not catch configuration changes, so once you know what you are doing, you can add this to the script:

    if environ['PATH_INFO'] == "/reload_config":
        theService = Service.load(cfgs)
        content = "Config reload OK"
        start_response('200 OK',[('Content-type','text/plain'),
                                 ('Pragma','no cache'),
                                 ('Cache-Control','no-cache, must-revalidate')])
        return content

Of course, you need to protect access to that url.

Hope this helps.

> -----Mensaje original-----
> De: tilecache-bounces at lists.osgeo.org
> [mailto:tilecache-bounces at lists.osgeo.org] En nombre de David Yeiser
> Enviado el: martes, 26 de octubre de 2010 19:30
> Para: tilecache at lists.osgeo.org
> Asunto: [Tilecache] Running Standalone under WSGI with
> tilecache_http_server.py
> Hello,
> I have a working GIS stack of Mapnik, Tilecache and
> OpenLayers. I'm new not only to web-based GIS but also
> Python, Linux, etc.
> Do I have to run the "python tilecache_http_server.py"
> command every time I want to use Tilecache?
> Can I place it in some startup file? I have a server from
> Slicehost and when I set it up according to their tutorials I
> added a file that gets run every time the server boots. Could
> I do something like that with this command? Something like:
> vi /etc/network/if-pre-up.d/run_tilecache_http_server.py
> # In run_tilecache_http_server.py there would be some code to
> start the server
> # Then I would do something like this:
> chmod +x /etc/network/if-pre-up.d/run_tilecache_http_server.py
> Would this work? Does it even make sense? Also, does running
> the Tilecache server constantly have any negative effects on
> the overall memory?
> Thank you!
> -David_______________________________________________
> Tilecache mailing list
> Tilecache at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/tilecache

More information about the Tilecache mailing list