Thursday, January 31, 2013

Bugzilla + nginx

Single question started everything - Which bug tracking app is best? One that just fits? I've chosen Bugzilla. Solution - I would think - ideal for sole developer.

Installation process was quite painless. Bugzilla was written in Perl so to install it I had to first install many dependencies - cause I've never really used Perl. After installation i was glad I could setup SQLite as data storage, but then I discovered dreadful problem - only mode which Bugzilla could be run with was CGI. I'm trying to use uWSGI wherever I can so in this case I was trying to run it with PSGI. Sadly the only supported modes are cgi and Apache's mod_perl. Happily both Nginx and uWSGI supports runing scripts as CGI. Then again - after configuration was done Bugzilla's main page was loading for about 3 seconds (server isn't that slow).

The Struggle began :)

Google quickly answered with issue for Bugzilla: https://bugzilla.mozilla.org/show_bug.cgi?id=316665 (note that it was created in 2005 ;) ). There is patch which adds support for FastCGI to Bugzilla (and possibly PSGI).

You can find same patch on GitHub: https://github.com/Stackato-Apps/bugzilla/blob/master/psgi.patch . From header one can deduce that it was written for version 4.0.3 (newest is 4.2.4).

Patch didn't apply successfully for newest version so, based on it, I've created updated one. The next step - configure uwsgi and start application. Application started without errors - even looked like was working properly - until I've wanted to log in. I've spotted strange error in logs - "no data". Additionally, page which was supposed to render was cut in half (and there was info about incorrect password/login).

Following new trail - no data on POST request at server side, I've luckily found another issue, this time it was for CGI-Emulate-PSGI.

Turns out the problem was just that - application doesn't receive POST data when uWSGI is used, fixing it looked easy... but I really don't know Perl :) And there is that bug with cutting page in half which can or cannot be related to first.

PSGI emulation from patch uses Plack so I possibly could use it to run app without uWSGI - on FastCGI which is supported by Nginx.

In short

Bugzilla as FastCGI application - the fast way.

  • Download Bugzilla package
  • Apply fastcgi patch
  • Configure BugzillÄ™ with checksetup.pl
  • Configure Nginx'a and start Plack service (files and commands below)

If you're using Gentoo Linux you can just add glorpen-overlay with patched ebuild for Bugzilla.

Final configuration

For Nginx:

#cgi leftovers - but why would anyone remove it?
location ~ ^(.*\.(jpe?g|gif|css|js|png|ico))$ {
        alias /srv/bugzilla/app/$1;
}

location  /  {
        include        fastcgi_params;
        fastcgi_param  SCRIPT_NAME      "";
        fastcgi_pass   unix:///srv/bugzilla/fastcgi.socket;
}

Starting Plack:

#!/bin/bash

d="/srv/bugzilla"
plackup -s FCGI -S "${d}"/fastcgi.socket "${d}"/app/app.psgi --pid "${d}"/plackup.pid -D

and lastly - stopping Plack:

#!/bin/bash

kill `cat /srv/bugzilla/plackup.pid`