Found most of my error, main issue is the

from flup.server.scgi import WSGIServer

should be:

from flup.server.fcgi import WSGIServer

Also had to make sure i didn't suckup the stdout data and send it to a
file (which I was doing for logging).

Now my only question is, this looks to me from my logs, like everytime
I get a request I seem to reinitialize the TG app (see all my tables,
captcha binds).  That seems really inefficient, does anyone know if re-
initialization is really happening, and how to avoid it?

James

On Sep 25, 9:20 pm, jostheim <[EMAIL PROTECTED]> wrote:
> Hi all-
>
> This might be a difficult question for people here to help me with,
> but I thought I'd give it a shot anyway.
>
> I am trying to get TG up and running on MediaTemple grid services.  I
> am interested in the grid aspects especially, and they support django
> already, give me shell access and have python 2.4 installed.  So I
> figured I'd give it a shot...
>
> Installing all the eggs was a breeze (well I have done this on several
> hosting providers, so I know what I am doing now).
>
> I can start up turbogears (on port 4000) no problem, wget gets valid
> pages.
>
> So I was then confronted with the problem of "how do I get this
> serving data on port 80?".  Well this is the sticking point.  I found
> a good description of doing this using FCGI with flup for django.
>
> https://forums.mediatemple.net/viewtopic.php?id=1371
>
> Then I found the turbogears page for  setting up fcgi with flup for
> lighthttpd.
>
> I cobbled together the following fcgi script, from some dreamhost
> wiki's and turbogears docs:
>
> #!/usr/bin/env python
> #
> # File name: tg_fastcgi.fcgi
> #
> # This module provides the glue for running TurboGears applications
> behind
> # FastCGI-enabled web servers. The code in this module depends on the
> fastcgi
> # module downloadable from here:
> #
> #http://www.saddi.com/software/py-lib/py-lib/fcgi.py
> #
> # NOTE: The fcgi.py file needs to be placed in a location that is on
> the
> # system path, such as the same the directory as the tg_fastcgi.py
> file
> # or in the base directory of the TG app code.
> #
> # To configure this module, please edit the three variables in the
> "USER EDIT
> # SECTION" before starting the TG application.  Also remember to edit
> the
> # top of this file with the correct Python installation information.
> #
> # 2006-04-17
> # ----------
> # * Updated for 0.9a4 by Mikael Jansson <[EMAIL PROTECTED]> for
> changes in
> #   config files.
> # * Removed hard TABs
> #
> import sys
>
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/setuptools-0.6c9-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/CherryPy-2.3.0-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/TurboGears-1.0.7-py2.4.egg/turbogears")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/flup-1.0.1-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/configobj-4.5.3-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/BeautifulSoup-3.0.7a-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/Cheetah-2.0.1-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/DecoratorTools-1.7-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/Extremes-1.1-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/FormEncode-1.0.1-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/PIL")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/Paste-1.7.1-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/PasteDeploy-1.3.2-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/PasteScript-1.6.3-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/PyProtocols-1.0a0-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/RuleDispatch-0.5a1.dev_r2506-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/SQLObject-0.10.2-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/TGCaptcha-0.11-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/TurboCheetah-1.0-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/TurboJson-1.1.4-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/TurboKid-1.0.4-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/Twisted-8.1.0-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/kid-0.9.6-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/python_twitter-0.5-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/pycrypto-2.0.1-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/registration-0.50-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/scgi-1.13-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/setuptools-0.6c9-py2.4.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/simplejson-1.9.3-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/zope.interface-3.4.1-py2.4-linux-i686.egg")
> sys.path.insert(0, "/home/51440/users/.home/lib/python2.4/site-
> packages/mx/Tidy")sys.path.insert(0, "/home/51440/users/.home/lib/
> python2.4/site-packages/mx/Number")
>
> import cherrypy
> import os
> from os.path import *
> import pkg_resources
> import turbogears
>
> pkg_resources.require("TurboGears")
>
> # -- START USER EDIT SECTION
> # -- Users must edit this section --
> code_dir = '/home/blah/users/.home/
> blah/'                               # (Required) The base directory
> of the TG app code.
> root_class_name = 'blah.controllers.Root'                        #
> (Required) The fully qualified Root class name.
> project_module_name = 'blah.config'  # (Required) The config module
> name. Replace
>                                             # PROJECTNAME with your
> project's name (e.g. wiki20).
> log_dir = ''                                # (Optional) The log
> directory. Default = code_dir.
> # -- END USER EDIT SECTION
>
> class VirtualPathFilter(object):
>     def on_start_resource(self):
>         if not cherrypy.config.get('virtual_path_filter.on', False):
>                 return
>         prefix = cherrypy.config.get('virtual_path_filter.prefix', '')
>         if not prefix:
>                 return
>
>         path = cherrypy.request.object_path
>         if path == prefix:
>                 path = '/'
>         elif path.startswith(prefix):
>                 path = path[len(prefix):]
>         else:
>                 raise cherrypy.NotFound(path)
>         cherrypy.request.object_path = path
>
> def tg_init():
>     """ Checks for the required data and initializes the application.
> """
>     global code_dir
>     global root_class_name
>     global log_dir
>     global project_module_name
>     last_mark = 0
>
>     # Input checks
>     if not code_dir or not isdir(code_dir):
>         raise ValueError("""The code directory setting is missing.
>                             The fastcgi code will be unable to find
>                             the TG code without this setting.""")
>
>     if not root_class_name:
>         raise ValueError("""The fully qualified root class name must
>                             be provided.""")
>
>     last_mark = root_class_name.rfind('.')
>
>     if (last_mark < 1) or (last_mark + 1) == len(root_class_name):
>         raise ValueError("""The user-defined class name is invalid.
>                             Please make sure to include a fully
>                             qualified class name for the root_class
>                             value (e.g.
> wiki20.controllers.Root).""")
>
>     sys.path.append(code_dir)
>
>     # Change the directory so the TG log file will not be written to
> the
>     # web app root.
>     if log_dir and isdir(log_dir):
>         os.chdir(log_dir)
>     else:
>         os.chdir(code_dir)
>         log_dir = code_dir
>
>     sys.stdout = open(join(log_dir, 'stdout.log'),'a')
>     sys.stderr = open(join(log_dir, 'stderr.log'),'a')
>
>     if exists(join(code_dir, "setup.py")):
>         turbogears.update_config(configfile=join(code_dir,
> "dev.cfg"),modulename=project_module_name)
>     else:
>         turbogears.update_config(configfile=join(code_dir,
> "prod.cfg"),modulename=project_module_name)
>
>     # Set environment to production to disable auto-reload and
>     # add virutal path information.
>     cherrypy.config.update({
>         'global': {'server.environment': 'production'},
>     '/' : { 'virtual_path_filter.on' : True,
>             'virtual_path_filter.prefix' : '/tg_fastcgi.fcgi' }
>         })
>
>     # Parse out the root class information for Cherrypy Root class.
> # add virutal path information.
>     cherrypy.config.update({
>         'global': {'server.environment': 'production'},
>     '/' : { 'virtual_path_filter.on' : True,
>             'virtual_path_filter.prefix' : '/tg_fastcgi.fcgi' },
>            'autoreload.on':False
>         })
>
>     # Parse out the root class information for Cherrypy Root class.
>     package_name = root_class_name[:last_mark]
>     class_name = root_class_name[last_mark+1:]
>     exec('from %s import %s as Root' % (package_name, class_name))
>     Root._cp_filters = [VirtualPathFilter()]
>     cherrypy.root = Root()
>
> # Main section -
> # Initialize the application, then start the server.
> tg_init()
>
> from flup.server.scgi import WSGIServer
> import atexit
> #from fcgi import WSGIServer
> if cherrypy.server.state == 0:
>         atexit.register(cherrypy.server.stop)
>         cherrypy.server.start(initOnly=True, serverClass=None)
>
> from cherrypy._cpwsgi import wsgiApp
> try:
>         WSGIServer(application=wsgiApp).run()
> except Exception, e:
>         print e
>
> Here is the issue, it does seem to work, it fires off  WSGI (I can see
> them in the logs), but then it just hangs.  When I go to hit the url
> again, I start seeing "Address already in use" errors, like it is
> trying to fire off the cherrpy server again...  What does this mean?
> Why is it trying to fire off more than one WSGIServer instance?  How
> does this work, how do my requests, which will all hit this script get
> to my WSGI/CherryPy/TG instance?
>
> I am 8 hours in and thouroughly confused, but I think this should
> work, it should be very similar to django, and evidently others have
> successfully run TG behind apache using the flub framework.
>
> Any help is hugely appreciated.
>
> James
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to