Auto Start + Django

Discussion in 'CGI/Perl/Python' started by iaihmb, May 27, 2007.

  1. iaihmb

    iaihmb New Member

    Basically, I'd like to get Django working with LiteSpeed and I'm willing to pay for someone's help. I've already got Django working with LiteSpeed with the following external application configuration:

    Code:
    Name: Django
    Address: UDS://home2/iaihmb/webapps/django/myproject.sock
    Max Connections: 50
    Initial Request Timeout (secs): 10
    Retry Timeout (secs): 5
    Everything else is set to its default value.

    This is where you come in, I'd like to use auto start. After finding this post I added/changed the following:

    Code:
    Max Connections: 20
    Autostart: Yes
    Command: /home2/iaihmb/webapps/django/myproject/manage.py runfcgi method=threaded socket=~/webapps/django/myproject.sock
    Back Log: I've tried 1, 50, and 100.
    Instances: 1 (I've tried 1, 500, and 1000.)
    Among other things I've also tried adding "daemonized=false" and removing "socket=~/webapps/django/myproject.sock" from the command but I always end up with the same error:

    ExtConn timed out while processing.

    If someone can help me with this problem today I'll donate $25 USD to their charity of choice or buy them something worth ~$25 USD from their Amazon wish list. :)
    Last edited: May 27, 2007
  2. mistwang

    mistwang LiteSpeed Staff

    Maybe manage.py does not work well, you need to create a file like below and start your app with that file, without any command line parameters.
    Code:
    #!/usr/bin/python
    import sys, os
    
    # Add a custom Python path.
    sys.path.insert(0, "/home/user/python")
    
    # Switch to the directory of your project. (Optional.)
    # os.chdir("/home/user/myproject")
    
    # Set the DJANGO_SETTINGS_MODULE environment variable.
    os.environ['DJANGO_SETTINGS_MODULE'] = "myproject.settings"
    
    from django.core.servers.fastcgi import runfastcgi
    runfastcgi(method="threaded", daemonize="false")
    I copied the code from django documentation which let Apache spawn django process.
  3. iaihmb

    iaihmb New Member

    I just tried that and it doesn't work and the same error is being logged. I've also tried this:

    Code:
    #!/usr/local/bin/python2.4
    
    from os import environ
    from sys import path
    
    from django.core.handlers.wsgi import WSGIHandler
    from fcgi import WSGIServer
    
    path += [
    	'/home2/iaihmb/lib/python2.4/',
    	'/home2/iaihmb/webapps/django/',
    ]
    
    environ['DJANGO_SETTINGS_MODULE'] = 'myproject.settings'
    
    WSGIServer(WSGIHandler()).run()
    Thanks for trying though. :)
  4. mistwang

    mistwang LiteSpeed Staff

    Is there anything in lsws/logs/error.log or lsws/logs/stderr.log, maybe you need to set some extra environment variables to make django happy.
  5. iaihmb

    iaihmb New Member

    Unfortunately there isn't.

    Debug logging is enabled and the control panel and error.log both show quite a few of these:

    I'm fooling around with it now, maybe I'll get lucky. :)

    Edit: I'm not sure if it's relevant but the UDS does get created.
  6. mistwang

    mistwang LiteSpeed Staff

    UDS socket is created by the server.
    Is the python process running, maybe it dies immediately.
    One way to trace it down is to use "strace" to trace the djyango process, command is like

    Code:
    strace -o strace.log <orignal FCGI command>
    You probably cannot use this command directly in the App configuration, just create a wrapper shell script.
  7. iaihmb

    iaihmb New Member

    Good catch, thanks! :D

    Even though the location of the Django module was added to the PYTHONPATH in the script that you found in Django's documentation it didn't work until I added it to the environment bit in the external application's configuration.

    Care to pick a charity or post the link to your Amazon wish list? :)
  8. mistwang

    mistwang LiteSpeed Staff

  9. iaihmb

    iaihmb New Member

    Benchmarks (Apache/mod_python and LiteSpeed/FastCGI.) and a new wiki entry coming soon. :)
  10. mistwang

    mistwang LiteSpeed Staff

    That's great! Thanks! :D

Share This Page