views:

465

answers:

2

I'm building a site for a client using django. It's been hosted on shared hosting and mod_wsgi can't be used. In the old year, I got it working using fcgi, but when I got back, it was broken.

I have replaced the fcgi script with a simple hello world script:

#!/usr/bin/python
def myapp(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/plain')])
    return ['Hello World!\n']

try:
    from flup.server.fcgi import WSGIServer
    WSGIServer(myapp).run()
except:
    import sys, traceback
    traceback.print_exc(file=open("errlog.txt","a"))

Tested and working on my local server, but on the hosted server, I get this error:

<title>FCGI Error</title>
A timeout occured while waiting for the script output (in: /usr/www/users/mymemb/).

If I look at the error log, I see this:

[Wed Jan  6 16:59:37 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 10 seconds

[Wed Jan  6 16:59:38 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 10 seconds

[Wed Jan  6 16:59:38 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" (user mymemb, gid 100) restarted (pid 1057)

[Wed Jan  6 16:59:38 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" (pid 1057) terminated by calling exit with status '118'

[Wed Jan  6 16:59:38 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 10 seconds

[Wed Jan  6 16:59:38 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 10 seconds

[Wed Jan  6 16:59:38 2010] [warn] FastCGI: (dynamic) server "/usr/www/users/mymemb/mymembers.fcgi" has failed to remain running for 30 seconds given 3 attempts, its restart interval has been backed off to 10 seconds

etc ...

If I ssh to the server, I can run the script fine, with the following output:

mymemb@www81:~/public_html$ ./mymembers.fcgi 
WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 200 OK
Content-Type: text/plain
Content-Length: 13

Hello World!

How do I fix this?

Added info:

It seems like the script is not running at all. If I add import x at the top of the script, and run it from ssh, I see that x.pyc gets created. If I rm x.pyc, and then hit the site, x.pyc does not get created.

I also noticed that the errors changed from

terminated by calling exit with status '118'

to

terminated by calling exit with status '116'

I wish I could find a reference for these exit statuses.

+1  A: 

The exit status 116 and 118 were coming from suexec. By reading the source code, I found that these errors are caused by the file/dir being writable by group or others, which suexec considers as a security issue. Removing write access from group fixed the problem.

Gary van der Merwe
+1  A: 

Hey, thanks! I'll just paste the comments.

  • What server are you using to run mymembers.fcgi ? – Tobu
  • Debian Etch, Apache 1.3 The url is mymembers.co.za – Gary van der Merwe
  • I suspect mod_fastcgi is misconfigured. Please post or pastebin the relevant parts of your apache config. – Tobu
  • As this is hosted on shared hosting, I did not think to look at the config. Looking at the config helped me find the problem, so you really helped me. I hope that I will be able to award the bounty to you. meta.stackoverflow.com/questions/35081/… – Gary van der Merwe
Tobu