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

9 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.

Add Your Comment



(optional)