Monit and Phusion Passenger

April 30th, 2011 No Comments »

While there’re multiple tools available for monitoring, ranging from Dan Bernshtein’s daemontools to God, I found that Monit is a pretty balanced solution. On one hand, it’s quite powerful, and on the other – it’s not resource hungry. The only drawback that I found, is that for monitoring a process, the process must have a pid-file saved somewhere. The Monit FAQ states that the programs which don’t have pid-file support should be run with some wrapper which will create it on their behalf.

I wanted to use Monit to monitor Rails’ instances, so if they grow too fat, Monit will take care of that. The problem is that the pid file that the Passenger creates a) doesn’t have a predictable location (there’s something called “generation” or something like that), and b) doesn’t have children, as those processes are detached.

Of course there exists a possibility of patching Passenger for providing such pid files. But, luckily, Passenger provides extension points in form of callbacks which are fired when the application instance is created and when it’s taken down.

It was trivial to use this API to provide pid-file managing. The result of this work was the “passenger_monit” plugin.

So, go ahead, add ‘gem “passenger_monit”‘ to your Gemfile and give it a try!

The source is available from:

MongoDB DLR support for Kannel

April 3rd, 2011 No Comments »

I wrote some code to make use of MongoDB as a DLR storage for Kannel SMS gateway.

The code is available on github:

ExtJS with Rails 3

March 6th, 2011 3 Comments »

In order to make ExtJS play nicely with Rails, the following tweaks are needed:

On the ExtJS javascript side, the following things are needed:

1. Ask server to server JSON:

Ext.Ajax.defaultHeaders = {'Accept': 'application/json'};

2. RailsJsonStore: = Ext.extend(, {
    constructor: function(config) {, Ext.applyIf(config, {
            messageProperty: 'message', //for store.reader.getMessage()
            restful: true,
            url: '/'+ config['root'] + 's',
            writer: {encode: false}

3. XSRF protection:

Ext.Ajax.on('beforerequest', function(o) {
        var csrf ="meta[name='csrf-token']").first();
        if (csrf) {
                o.defaultHeaders = Ext.apply(o.defaultHeaders || {}, {'X-CSRF-Token': csrf.getAttribute('content')});

On Rails side:

config.active_record.include_root_in_json = false

Integrating Rails and dhtmlxTabbar

June 24th, 2008 2 Comments »

The dhtmlxTabbar is a nice tab-bar component from
In order to use the AJAX loading feature I had to make a small change in the dhtmlxcommon.js so it mimics the behavior of Prototype by adding a X-Requested-With HTTP header. Thus, it’s possible to use request.xhr? in Rails.