Acts As Ferret DrbServer Win32 Service
My last Ruby on Rails project, I implemented a full text search using acts_as_ferret (AAF). For the production environment, I used AAF DrbServer for centralised access to the index files, or you probably will scratch your head, bumping into an error message similar to this, due to concurrent manipulation of Ferret index files:
File Not Found Error occured: tried to open "/[app_name]/[model]\_8e_0.del" but it doesn't exist: <No such file or directory>
It is easy to start/stop AAF DrbServer on Unix environment using a simple shell script as shown in the help page. Creating similar script for windows should not be too difficult, but running it in a command console, is usually a no-no for the system administrator. So the workaround is you have to create a Win32 service for AAF DrbServer.
I scoured the web hoping that someone had done the dirty job, but not my lucky day, the closest I found was an article by Sausheong on how to create a Win32 service on Rails. Picking up from there, I created some scripts that allows you to install/remove Ferret DrbServer as Win32 service through simple commands.
Let’s get started:
- Make sure you have installed acts_as_ferret.
- Install win32-service gem.
gem install win32-service
- Download ferret_win32_service.zip and extract
ferret_serviceandferret_daemonto[app_name]/scriptdirectory.ferret_servicescript is to install/remove/start/stop your win32 service, whileferret_daemonscript is to be callled by Win32 service to start/stop the DrbServer. - To remove an installed service:
ruby script/ferret_service remove -n [service_name]
- To start/stop a service:
ruby script/ferret_service start|stop -n [service_name] // or you can also run: net start|stop [service_name]
To install AAF DrbServer as Win32 service:
Usage: ruby script/ferret_service install [options]
-n, --name=NAME Service name
-d, --display=NAME Service display name
-l, --log FILE Service log file
-e, --environment ENV Rails environment
-t, --trace Display stack trace when exception thrown
-h, --help Show this help message
Example:
ruby script/ferret_service install -n [service_name] -e production
By default, ferret_daemon will create [app]/log/ferret_service_[environment].log file, unless it is overwritten when installing the service using the -l or --log option. The log file will show the trace of the service status, if it is has been started, stopped or currently listening.
ferret_daemon deamon is to be called by win-32 service, but if you need to run in on command console, use can use the -c or --console option:
ruby script/ferret_daemon -c -e [environment]
If you need to create any DrbServer as windows service, you can always take a quick look at ferret_service and ferret_daemon scripts for reference. So fear not for Win32 service.
UPDATE (Nov 27, 2007)
The scripst are now part of acts_as_ferret 0.4.3. Thanks Jens.
UPDATE (Jan 31, 2008):
You may face a problem that the service can’t be started properly after a server reboot, with “..did not respond in a timely fashion…” message in the event log. I faced the same issue as well, banging my head against the wall a couple of times. And this was what I did.
By default, the Win32 service will timeout if it doesn’t complete the start process within 30 seconds; starting rails acts_as_ferret service on windows can be quite slow, especially after server reboot, when there are so many services to be started at the same time.
So I increase the timeout to 120 seconds, just to be sure, as previous attempt to set it at 60 seconds still failed occasionally. Follow to link below on how to do that:
http://support.microsoft.com/kb/839803
The other step that I did as another preventive measure, is to configure the service to restart on failure for the first, second and subsequent failures, and configured the restart service period to be 7 minutes between each failure, to give some ample time for the server to off load the heavy CPU usage after reboot. You can do that by double click on the service name from control panel, under the Recovery tab.
And lastly, good luck. :)

Add Your Comment