Skip to main content

Running ferret server with mongrel and shared index folder

If you are using acts_as_ferret plugin for searching in your rails application then you must have faced some issues with indexing or running ferret server on your production server. In this post, I will share with you some tips about running and maintaining ferret server:
  • Running ferret server on production
  • Sharing your ferret index folder
  • Write a simple script to re-index all your data

Running your ferret server
If you have multiple instances of mongrel running in your production, then you must need to run the ferret server to handle situations when multiple processes are updating ferret index at the same time. If you want to run ferret server in your production server, then at first you have to open the port you set in ferret_server.yml of your config directory on the server you want to run it. acts_as_ferret comes with a built-in drb server which uses dRuby protocol. So, you should remember to open the port with other protocol (not http or something else). One very important thing is to change the following section of your /vendor/plugins/acts_as_ferret/lib/server_manager.rb as follows:
require(File.join(File.dirname(__FILE__), '../../../../config/environment'))
#require(File.join(File.dirname(ENV['_']), '../config/environment'))

Make sure you run the ferret server before running mongrel or apache. Now you can start the ferret server with the following command:
ruby /{YOUR_APP_DIRECTORY}/script/ferret_server -e production start

Also, the you can stop your ferret server with the following command:
ruby /{YOUR_APP_DIRECTORY}/script/ferret_server -e production stop

After you have started you ferret server you can start your mongrel and apache server. When mongrel is being started it checks for index folder in your app directory. If it does not find one it creates one. So, it’s possible that you will have different index folder with each deployment which is costly and re-indexing every time after your deployment is not at all a good solution.

Sharing your ferret index folder
You can set a default index folder in your production server which will be shared. To do this create a folder with read/write permission and create symlink to this folder each time you deploy and before starting the server. If you are using Capistrano for your deployment then make sure to run the symlink creation script before starting mongrel/apache. Otherwise the index folder will be created with the start of mongrel. A sample script could be like this:

run "ln -s /mnt/app/shared/ferret/ /mnt/app/current/index"

A simple script for ferret re-indexing
Here is a sample rake task for re-indexing your application data:
desc "Updates the ferret index for the application."
task :ferret_index => [ :environment ] do | t |
puts "Completed Index Rebuild of Model1 model"
puts "Completed Index Rebuild of Model2 model"
puts "Completed Index Rebuild of Model3 model"

To run rake task use the command:
rake ferret_index RAILS_ENV=environment

Make sure to restart your mongrel and apache server to point to the newer version of the index folder created within the directory you set after re-indexing is completed.


Post a Comment

Popular posts from this blog

The contents of the feature's solution requires the Solution Sandbox service to be running

If you are developing any Sandbox solution for Sharepoint 2010, then you may have faced an error while deploying any solution to your development server. The error in Visual Studio 2010 output window looks like this generally:
Error occurred in deployment step 'Activate Features': This feature cannot be activated at this time. The contents of the feature's solution requires the Solution Sandbox service to be running.

The fix is simple. You must make sure that your "Sharepoint 2010 User Code Host" service is running. It is disabled by default installation. So, you have enable and run it. If you want to deploy the solution, then again you see the same error output. Actually, you have to make sure that this service's status is active in Central Administration Site. To see the status go to your Sharepoint 2010 Central Administration Application. Under System Settings > Manage services on server make sure that "Microsoft SharePoint Foundation Sandboxed Code…

A first look at Microsoft ASP.NET MVC 3 Beta

First beta version of Microsoft ASP.NET MVC framework 3 is ready to be downloaded from here and announcement from Scott Guthrie's blog. Significant changes have already been made to this version. You can go through the release documentation to have detail information on the new changes that are available with this release.

One of the newest edition is the "NuPack Package Manager". If you are a ruby developer, then it will not be a real ground-breaking idea as you are already using RubyGem from the first day of your ruby development career. For .NET platform it's comparatively newer concept. There are few other open source project already available for the same purpose. But there is always a better expectation associated with something from Microsoft itself from developers point of view. To read more on NuPack refere to the this article from Scott Hanselman. With this release Microsoft is going to make integration of third party libraries with .NET easier.

The new vie…

Can not install Devise gem with Ruby 1.9.2 on windows

I was having a try out of devise gem with one of my Rails 3 pet project just yesterday. I installed Ruby 1.9.2 with the one-click installer from and the latest Rails 3.0. But I faced installation problem as usual on windows. The problem was that it was not being able to build its native extensions.
After some research I found out the solution at What I was missing is development kit. I just followed the instruction and it was solved and installed devise with my Ruby 1.9.2 correctly.
But I am not sure whether it will work with Rails 3's bundle install command or not. I installed the gem from command line using the command gem install devise --platform=ruby before installing all the required gems with bundle install command . The last parameter platform is a must as it will temporarily use the DevKit to build native extensions. That's it.