2

I'm attempting to deploy a flask web app I've developed using cherokee and uwsgi. I got cherokee and uwsgi installed and working (i think uwsgi works), but when I configure the app in cherokee, i just get an error saying uWSGI Error wsgi application not found. I used an xml config file (I think you need to with cherokee), and that contains this:

<uwsgi>
    <pythonpath>/srv/mobile-site/app/</pythonpath>
    <app mountpoint="/">
        <module>mobilecms</module>
        <callable>app</callable>
    </app>
</uwsgi>

My flask app is obviouly in the /srv/mobile-site/app/ folder with the main script being mobilecms.py.

Is there something wrong with this file? Would permission errors cause this? Thanks in advance for any help!

Tom Brunoli
  • 3,436
  • 9
  • 36
  • 54

2 Answers2

2

Always try uWSGI deploy without a webserver, before going in production.

uwsgi -x <xmlfile>

It will print a lot of information/errors

roberto
  • 144
  • 1
  • 3
2

Roberto's suggestion is a good one; it will help diagnose where the error is occurring (i.e. whether it's uWSGI or Cherokee).

I've also recently fought to get uWSGI and Cherokee to work together. I ended up configuring the uWSGI source in Cherokee manually:

  • In Cherokee Admin, under the "Sources" tab, add a new source with nickname "uWSGI Source" and socket "/tmp/foo.sock"
    • Change the type to "Local Interpreter"
    • In the interpreter field, enter: /usr/local/bin/uwsgi -x /path/to/uwsgiconfig.xml
  • In rule management for the virtual server, click to add a new behaviour rule.
    • Choose a manual configuration of type "Directory" with a path of "/"
    • Set the handler to "uWSGI"
    • Scroll to the bottom and set "Round Robin" for the balancer
    • Add the "uWSGI Source" information source
  • Save changes and restart Cherokee

In my uWSGI config file I have something like this (adapted to your example):

<uwsgi>
    <chdir>/srv/mobile-site/app/</chdir>
    <wsgi-file>/srv/mobile-site/app/mobilecms.py</wsgi-file>
    <callable>app</callable>

    <socket>/tmp/foo.sock</socket>
    <chmod-socket>666</chmod-socket>

    <master />
    <processes>1</processes>

    <disable-logging /><!-- Errors are still logged; this just disables request logging which Cherokee takes care of -->

    <vacuum />
    <no-orphans />
</uwsgi>

Note that the Cherokee uWSGI wizard doesn't accept this as a valid configuration file (hence the manual configuration).

Cameron
  • 96,106
  • 25
  • 196
  • 225
  • I've done this, and I get a 503 error now. I tried the `uwsgi -x` thing on a prompt and i now get this error: `fopen(): No such file or directory [uwsgi.c line 2769]` – Tom Brunoli Feb 27 '11 at 07:36
  • @tominated: Hmm. You need to figure out which file/directory cannot be found. Try removing the chdir, the wsgi-file, and the socket options one by one to see which one is causing the error (probably not the socket). Make sure the permissions on your directory and files are set to read-write for world (i.e. xx6 or xx7) – Cameron Feb 27 '11 at 19:49
  • @tominated: Actually, I had a look at that line in the source and it means that there was an error opening your main WSGI file (`/srv/mobile-site/app/mobilecms.py`). Double-check it exists and that it is world readable (use `ls -l` to view the permissions and `chmod a+r mobilecms.py` to add the readable permission for all) – Cameron Feb 28 '11 at 03:59
  • I got uwsgi working nicely now! thanks for that! but now cherokee just gives me a 500 internal error. I checked the error logs and it they are empty – Tom Brunoli Feb 28 '11 at 10:14
  • @tomintated: Try restarting the machine, then starting Cherokee again -- on the first request, you should see Cherokee starting uWSGI in the error log. This will show what's going on. The error log should not be empty -- check under the logging tab of your vServer that your log file is setup properly – Cameron Feb 28 '11 at 16:14
  • OK i fixed it. I stupidly forgot to initialise the database. Thanks for all the help though, Cameron! – Tom Brunoli Mar 02 '11 at 05:07
  • One more thing, what should i set in the behaviours of the vhost so that everything that isn't / works? – Tom Brunoli Mar 02 '11 at 05:12
  • @tominated: No problem :-) I'm not 100% sure what you mean about the behaviours though -- is your uWSGI app only receiving requests for `/`? Your uWSGI handler should be on a Directory rule with `/` set as the "Web Directory" parameter. This causes all sub-paths (e.g. `/foo/bar`) to be routed through that handler (except if there's a matching rule with higher priority, of course). – Cameron Mar 02 '11 at 14:35
  • well, i have the directory rule set up nicely, but when i try access other pages on my app (for example /admin) it just shows up the front page. – Tom Brunoli Mar 02 '11 at 23:23
  • @tominated: Hmm. Sounds like it might be a problem with the app itself not routing requests properly. Logging might help you see what's going on (you can print path values, debug statements when your functions are called, etc. to see where the execution flow is going and why). Anything you print to stderr or even stdout should show up in the server error log (you can use `tail -f logfile.log` at a shell prompt to see the output in real-time) – Cameron Mar 03 '11 at 04:09
  • well, it works perfectly when running it locally. I'll check it when I get home, though. – Tom Brunoli Mar 03 '11 at 05:34
  • @tominated: Definitely weird, then. You might be in for some heavy debugging ;-) – Cameron Mar 03 '11 at 06:50
  • I decided to scrap cherokee and uwsgi completely and go with nginx and gevent. Now it works perfectly. I just have to make gevent start up when the server does. – Tom Brunoli Mar 04 '11 at 04:49