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:

  1. Make sure you have installed acts_as_ferret.
  2. Install win32-service gem.
    gem install win32-service
  3. Download ferret_win32_service.zip and extract ferret_service and ferret_daemon to [app_name]/script directory.

    ferret_service script is to install/remove/start/stop your win32 service, while ferret_daemon script is to be callled by Win32 service to start/stop the DrbServer.

  4. 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 
  5. To remove an installed service:
    ruby script/ferret_service remove -n [service_name]
  6. To start/stop a service:
    ruby script/ferret_service start|stop -n [service_name]
    
    // or you can also run:
    net start|stop [service_name]
    

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. :)

14 Comments . Comments Feed . Trackback URI
Tue, 28 Aug 07 05:02 pm . neongrau wrote:

i was happy when i found your page about runnin ferret as a windows service. but sadly i can’t get the service to start.

everytime it fails with: “Error 1053: The service did not respond to the start or control request in a timely fashion.”

while exactly the same call to ferret_daemon with the “-c” switch runs fine. i don’t see any reason to fail in the logs and normally the timeout seems to be way too quick. afaik windows should give the service 30secs. it’s taking a few sconds to start on console, but nowhere near 30 seconds. do you have any idea?

Tue, 28 Aug 07 07:37 pm . Herryanto Siatono wrote:

Yeah, windows stops services that take more that 30 seconds to start.

Can you cross check wat’s the setting of ServicesPipeTimeout, just to be sure, and increase it to 60 seconds if needed to. http://support.microsoft.com/kb/839803

And take a look at log/ferret_service_[env].log file, check out where it’s failing too.

Tue, 6 Nov 07 08:45 pm . Luke Pearce wrote:

Just a quick note on this; I had a similar error message when trying to start from the services app. However when you run from the command line you can get extended error messages.

In my case I had moved some files and had a required file dependancy.

Cheers
Luke

Sat, 29 Dec 07 05:52 am . Roger Pack wrote:

Appears aaf 0.4.3 doesn’t really work with win32 yet, as it uses fork. You can go into it and take out the fork call and make some other modifications (among which are requiring ‘rubygems’ at the top fo these files, taking off set_ssid, etc., etc., within aaf. and then you have a fake guy that does it. That with downloading backgroundrb that is old enough to work with windows. I have a blog entry about it at http://betterlogic.com/roger/?p=120 but it’s still iffy.

Thu, 31 Jan 08 12:09 am . neongrau wrote:

there was some change in the start/stop scripts
“unified drb server” that broke s.th. on windows. i had that problem a while ago and went back to aaf svn rev. 257.
haven’t yet checked if it’s fixed.

but i have a problem with the service i really need to fix. the problem is that the service won’t start automatically on system boot. it always fails with the classic “..did not repsond in a timely fashion…” in eventlog. starting it manually generally works (well most of the time, sometimes i need a second try to start it).

anyone any idea what the problem could be? perhaps something in PATH thats not available at that time?

Thu, 31 Jan 08 05:39 pm . Herryanto Siatono wrote:

@neongrau, I’m not sure what went wrong with script found in ferret, haven’t got the time to try it out.

As regarding the service startup problem, please refer to my last updated note above. Hope it helps.

Thu, 3 Apr 08 05:26 pm . neongrau wrote:

@Herryanto, just saw your tip today.

while this seems to work on my dev machine running XP on my test server (2003 server) it’s still not working. somehow weird, i tested with 2 and 3 minutes 120000 and 360000ms as a value for ServicesPipeTimeout without luck.

so i tested one last time with a value of 3.600.000 ms (1 hour). but i get exactly the same error instantly when booting up. i would’ve expected it to just take ages to start. but it failed right away, even in eventlog i see the fail message just 90 seconds after the first entry from that boot.

the german error message:
Zeitüberschreitung (3600000 ms) beim Verbindungsversuch mit Dienst InformerSearch_latest.

Weitere Informationen über die Hilfe- und Supportdienste erhalten Sie unter http://go.microsoft.com/fwlink/events.asp.

Thu, 3 Apr 08 07:12 pm . neongrau wrote:

since i badly needed a solution i’ve now found this workaround to get it to work:

create a dependency to a default service that already starts late like messenger (or spooler)

make sure that service is set to auto start (i was used to disable it right away)…

sc config messenger start= auto
sc config *aaf_drb_service_name* start= auto depend= messenger

Thu, 3 Apr 08 10:09 pm . Herryanto Siatono wrote:

Thanks Neon, I wish I could help, I think that’s a nice workaround too, so long that your service can be successfully started up after a reboot.

Fri, 13 Jun 08 11:11 pm . Karthik wrote:

Guys,

I have been at this for 3 days now with no luck getting a DRb server
going. I have a production site on a Windows box with Apache, 5 mongrels
and using aaf rev. 257 (as suggested here) and ferret 0.11.4 (mswin32).

I cannot even get ferret_daemon going on the console.

ruby script/ferret_daemon -c -e production

gives me

Initializing FerretDaemon…
Starting Ferret DRb server…
script/ferret_daemon:69:in `service_init’: undefined method `start’ for
ActsAsFe
rret::Remote::Server:Class (NoMethodError)
from script/ferret_daemon:51:in `initialize’
from script/ferret_daemon:87:in `new’
from script/ferret_daemon:87

I have tried everything … or so it seems. Various versions of ferret
and aaf have been installed, uninstalled, patched and burnt… no luck.

Any help will be much appreciated.

Thank you,

Karthik

Thu, 19 Jun 08 02:34 pm . Herryanto Siatono wrote:

That’s really strange can you try to run on rails console, if you can load ferret server class, cross check in acs_as_ferret plugin files, for Server class, etc…

>> ActsAsFerret::Remote::Server

Mon, 30 Jun 08 03:31 pm . “Acts As Ferret DrbServer Win32 Service” « “golb ecruos nepo”.reverse wrote:

[…] June 30, 2008 at 12:19 pm · Filed under acts as ferret, acts_as_ferret for windows, ferret server on windows, rails, ror, ruby on rails ·Tagged acts as ferret, acts_as_ferret for windows, ferret server on windows, rails, ror, ruby on rails How to setup acts_as_ferret on windows was what I was wondering when I came accross this link. […]

Fri, 24 Apr 09 02:43 pm . Niels wrote:

Hi, when I try start the daemon from the command prompt, I keep getting the error “uninitialized constant Ferret::Daemon” (see below).
After more then 4 hours searching, I still don’t have a clue why. Somehow the Daemon constant seems to be missing from the Ferret module. Would anybody know why?

thanks for any hints
Niels

c:\Data\rails\doctservice\doctservice>ruby script/ferret_daemon.rb -c
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:440:in `load_missing_constant’: uninitialized constant Ferret::Daemon (NameError)
from c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:80:in `const_missing’
from script/ferret_daemon.rb:33

Sun, 26 Jul 09 02:57 am . Mike Smith wrote:

I needed to run ferret_server for testing purposes. Here is a quick fix for the existing problems per July 2009.

1. If you use win32-service gem 0.7.0 version (the only one available now) the old way to create a service will not work. Replace the install function in ferret_service with the following:

def install

begin
if Service.exists?(@options[:name])
puts “Service name ‘#{@options[:name]}’ already exists.”
return
end

Service.create(
:service_name => @options[:name],
:service_type => Service::WIN32_OWN_PROCESS,
:description => ‘ferret service’,
:start_type => Service::AUTO_START,
:error_control => Service::ERROR_NORMAL,
:binary_path_name => binary_path_name,
:dependencies => “”,
:display_name => @options[:display]
)
puts “‘#{@options[:name]}’ service installed.”
rescue => e
handle_error(e)
end
end

2. In ferret_daemon there is a dependency missing. The dependencies are:

require ‘optparse’
require ‘win32/service’
require ‘win32/daemon’

3. acts_as_ferret start function is not compatible anymore with ferret_daemon. A quick fix for this (without changing the revision to 257) is to change the service_init function:

def service_init
cfg = ActsAsFerret::Remote::Config.new
remote_server = ActsAsFerret::Remote::Server.new
log “Starting Ferret DRb server at #{cfg.uri}…”
remote_server.class.running = true
DRb.start_service(cfg.uri, remote_server)
log “FerretDaemon started.”
end

It’s all quite hacky but I needed the server just for testing. BTW, I didn’t get the service to run (it kept timing out no matter what ServicesPipeTimeout I put). But if I started the daemon, it was sufficient to run the server and it is running fine.

Add Your Comment



(optional)