Patching Rails Edge to stay bug free

Manfred Stienstra, 11 Oct 2007, 21:39 in ruby on rails and tools (edit).

A lot of people are on Rails Edge nowadays. Besides all the nifty new features they also encounter bugs. There are two ways to work around these bugs:

  1. Lock your Rails external to an older revision or freeze it to vendor
  2. Find a patch on Trac or write one of your own and apply it

If you decide to apply patches, you’re going to need some help. Our solution is to put all the patches that need to be applied in vendor/patches and put the following Rake task in lib/tasks/patches.rake:

task :patch => 'patches:apply'

namespace :patches do
  desc "Apply all patches from vendor/patches to root"
  task :apply do
    Dir.chdir(RAILS_ROOT) do
      Dir["vendor/patches/*"].each do |patch|
        system "patch -p0 < \"#{patch}\""
      end
    end
  end

  desc "Revert all patches applied in vendor/plugins and vendor/rails" +
       "through SVN"
  task :revert do
    system "svn revert --recursive vendor/plugins vendor/rails"
  end
end

Assuming you’re using Capistrano 2, you can add the following to your deployment recipe to automatically run the patches for each deployment.


after "deploy:update_code", "deploy:patch"

namespace :deploy do
  task :patch, :roles => :app do
    run "rake patches:apply"
  end
end

Now all you have to do is make sure that all the patches apply cleanly and remove them when they’re accepted into Rails.

No comments yet

Quiz

Thijs van der Vossen, 23 Oct 2006, 15:39 in ruby on rails, tools, and launches (edit).

This is from a nice new app we’ve been working on for the last month or so. Any idea what it is and who we’re building this for?

Sneak peek

Update: First right answer gets two great books. Can’t tell you what they are about without giving away the answer, I’m afraid…

17 comments

Fcgimon updated

Manfred Stienstra, 28 Aug 2006, 16:50 in ruby on rails and tools (edit).

In march I wrote a post about our fcgi monitoring and management tool Fcgimon. Today I fixed some rough edges and decided to call this version 1.0.

The biggest change is the way Fcgimon gathers and presents it’s data from `ps`. Earlier versions would just find all the dispatchers and spawners in the process list and show them. This means that not running application would just not show up in the list. Fcgimon now shows the status of all the configured projects, which makes it easier to detect broken spawners. Fcgimon will still show all fcgi processes and spawners outside of the configured projects, but under the normal list and with a small warning.

Minor changes include memory usage information and in general nicer output.

screenshot of fcgimon

If you like what you see you can download Fcgimon from our Subversion repository.

https://fngtps.com/svn/server-scripts/trunk/fcgimon/

2 comments

Basic Authentication for Camping

Manfred Stienstra, 19 May 2006, 17:35 in tools and web (edit).

This week I wrote a small web tool in Camping but when I wanted to secure it a little bit I noticed that there was no default way to do HTTP basic authentication. So I wrote some code to do just that. Actually I wrote a lot of documentation and a little bit of code.

With just some downloading and three simple steps you can add basic authentication to you application.

Download the basic_authentication.rb file.

  1. require 'basic_authentication'
  2. Mixin the BasicAuth module:
    module Blog
      include Camping::BasicAuth
    end
  3. Define how you want to authenticate users:
    module Blog
      def authenticate(u, p)
        [u,p] == ['admin','secret']
      end
      module_function :authenticate
    end

And you’re ready to start not letting people into you application. If anyone has a better idea on how and where to define the authenticate method, please drop me a line.

You can use this code under the same restrictions as the Camping framework. Now let’s just hope Why doesn’t sue me for using the Camping module (:

Update: Thijs found a bug in the header handling. The link above has been updated. I will try to give this code a home somewhere and some proper version information when I have some time.

9 comments

Monitoring and managing fcgi processes using fcgimon

Manfred Stienstra, 16 Mar 2006, 17:25 in ruby on rails and tools (edit).

When we started using Switchtower Capistrano to deploy our projects, we had some trouble with Lighttpd herding the fcgi processes. Because the standard Capistrano tasks expect the processes to be managed externally anyway, we decided to stop using Lighttpd for this.

Most of the existing tools for managing fcgi processes are designed to do complex stuff like load balancing across different servers. What we needed was a simple tool for managing multiple Rails applications on a single server. So we wrote Fcgimon.

Fcgimon manages fcgi processes using the spinner and spawner scripts that come with Ruby On Rails.

FCGIMon screenshot

You specify all Rails applications and the number of fcgi processes you want to have running in a configuration file. Then use fcgimon to start or stop all fcgi processes for any single application, or start and stop all applications at once.

Fcgimon also generates snippets that can be included in the main Lighttpd configuration file. This makes it much easier to keep the number of running fcgi processes and the ports listed in the Lighttpd configuration file in sync.

You can download the latest version of Fcgimon from our Subversion repository. Please give it a try and tell us what you think.

2 comments

What is your Textmate serial number?

Thijs van der Vossen, 06 Jan 2006, 20:23 in tools (edit).

Allan on the sales figures for Textmate:

[…] the serial number on your license (should you have bought one) is the actual customer number, so this will tell you how many licenses were sold before you purchased yours.

I’ve got 619. What’s your number?

12 comments

Vim and TextMate followup

Manfred Stienstra, 04 Jan 2006, 15:35 in tools (edit).

Yesterday Kevin dropped a message asking for more vim mapping.

I was wondering how much could be done using vim scripts, it looks like I wasn’t the only one. Felix Ingram apparently created a TextMate snippet emulation script, as far as I can see it’s a script to emulate the tabbing through arguments in a snippet.

No comments yet

TextMate addi(c)tions

Manfred Stienstra, 16 Dec 2005, 11:08 in ruby on rails and tools (edit).

For the last few months I’ve been using TextMate on my iBook and on the Lil’ Mac at work. I’ve grown accustomed to the various ‘insert snippet’ commands available in TextMate. Unfortunately Vim doesn’t have these commands and I find myself inserting ^Z in my views.

However, Vim configuration is powerful enough to implement these commands. Make sure you’re in command mode and do the following:

:imap <C-z> <lt>%=  %><Left><Left><Left>
:imap <C-x> <lt>%  %><Left><Left><Left>

This will allow you to insert <%= %> and <% %> into your files during insert mode. It is also possible to insert these commands in ~/.vimrc so you don’t have to define them every time you launch vim.

You can find the other mapping syntax rules on the vim.org website and in your vim help files.

3 comments