tatlar
tatlar

Reputation: 3176

Troubleshooting Dreamhost + Passenger + Django

I have a website that was happily running on Dreamhost + Passenger + Django for several years. Recently (last Thursday) it looks like Dreamhost updated Passenger under the hood without notifying me, and this has caused the website to go down.

Here is the installed (hosted) Passenger directory:

$ pwd
/dh/nginx/passenger
$ ls -la
total 32
drwxr-xr-x 12 root root 4096 2014-05-15 13:40 .
drwxr-xr-x  6 root root   76 2012-06-27 17:54 ..
-rw-r--r--  1 root root 1056 2013-10-26 15:00 LICENSE
drwxr-xr-x  2 root root 4096 2014-05-15 13:40 bin
drwxr-xr-x  7 root root   92 2014-05-15 13:40 buildout
drwxr-xr-x  2 root root 4096 2014-05-15 13:40 dev
drwxr-xr-x  5 root root 4096 2014-05-15 13:40 doc
drwxr-xr-x 10 root root  139 2014-05-15 13:40 ext
drwxr-xr-x  3 root root 4096 2014-05-15 13:40 helper-scripts
drwxr-xr-x  3 root root   69 2014-05-15 13:40 lib
drwxr-xr-x  2 root root  137 2014-05-15 13:40 man
drwxr-xr-x  3 root root   38 2014-05-15 13:40 node_lib
-rw-r--r--  1 root root 1243 2013-10-26 15:00 passenger.gemspec
drwxr-xr-x  4 root root 4096 2014-05-15 13:40 resources

These file updates approximate to the time the site went down.

I thought it might be a simple case of restarting Passenger by touch-ing /path/to/app/tmp/restart.txt however that does not seem to have worked. Any ideas how I can troubleshoot this?

Thanks in advance.

Edit 1: The web server is Nginx. I assume that I can just reload Nginx and that will refresh all connections through Passenger?

sudo /etc/init.d/nginx reload

Edit 2: The file in question that throws the error is:

/dh/nginx/passenger/helper-scripts/wsgi-loader.py

with the error:

File "/dh/nginx/passenger/helper-scripts/wsgi-loader.py", line 171
    buf = b''
            ^

SyntaxError: invalid syntax

Interestingly, although it looks like Passenger was updated on 2014-05-15, all these helper scripts date back to 2013-10-26. Is it something simple like these helper scripts are out of date with the newly installed version of Passenger? I had thought that Passenger itself was language agnostic?

Edit 3: The virtualenv being ignored

So, the system installed version of Python is 2.5.2, but my virtualenv Python I have built the application in is 2.6.8. So this error shouldn't even be showing up. I have added my 2.6.8 Python interpreter as per the instructions but it is still not working and the error message still suggests that the old Python interpreter is being used. Any ideas?

Edit 4: The correct (and valid) virtualenv Python interpreter is being used (2.6.8)

import sys, os
INTERP = "/home/<user>/venv/tcs/bin/python2.6"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
# print(sys.version)
sys.path.append(os.getcwd())
sys.path.append(os.path.join(os.getcwd(), '/home/<user>/<application>/<dir>'))
os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

(<user>, <application> and <dir> hidden for obvious reasons)

When I uncomment the print(sys.version) I get the following output:

2.6.8 (unknown, Jul 10 2012, 08:03:16)
[GCC 4.3.2]

Upvotes: 3

Views: 833

Answers (2)

tatlar
tatlar

Reputation: 3176

I asked this same question on the Phusion Passenger list and Hongli also answered me there (thanks Hongli!!):

https://groups.google.com/forum/#!topic/phusion-passenger/cYBgUPX_ICA

Dreamhost's documentation is out-of-date, and their support team is not well versed in Phusion Passenger configs/issues.

It turns out that Passenger also requires at least Python 2.6 to even start up (if you are using it for Python apps or frameworks like Django), prior to loading your defined virtualenv Python interpreter in your passenger_wsgi.py file. To make this happen you need to modify how Nginx is configured...

Edit your Nginx config file (nginx.conf) and add the following line:

http {
    passenger_root ...;

    # Use Python 2.6 by default.
    passenger_python /home/<user>/venv/<venv-name>/bin/python2.6;


    server {
        <snip>
    }
}

This forces Passenger to use the defined Python interpreter in passenger_python for starting up. Voila! - a running webserver once again.

Relevant anchor in the Phusion Passenger Nginx webpage

Upvotes: 1

Hongli
Hongli

Reputation: 18924

It looks like you are running Python 2.5 or earlier, which did not support the byte string declaration syntax. Phusion Passenger requires Python 2.6 or later.

Upvotes: 2

Related Questions