On Fri, 13 Aug 2004 09:50:58 +0900, Mehr, Assaph (Assaph)
wrote:

> Hi All,
>
> The service installs and start fine, but cannot be stopped
> (the process has to be manually killed). I have tried
> specifying various termination signals (using --termsig) and
> using a Kernel#trap to respond to them, but the trap is never
> executed, and the process doesn't stop. E.g.: trap("TERM") {
> @server.shutdown; exit(0) }
>
> The only signal that stops the process is SIGSEGV, which
> isn't very nice :P. Besides, even traps for it don't work.
>
> Any clues as to how to fix?

It's probably due to the fact that the Ruby interpreter
releases control to Windows when it waits for events. So you
have to have an event on a regular basis... 

I've had the same problem with a TCPServer and came up with the
following hack:

         # The hack...

 def self.trap(signal)
   Kernel::trap(signal){yield}
   Thread.new{loop{sleep 1}} # Stupid Windows...
 end
 
         # Doesn't work with Kernel.trap .
         # Try it!

 trap("INT"){puts "Terminating..." ; exit}

         # Just a demo...

 require "socket"
 puts "Hit ^C..."
 TCPServer.new("0.0.0.0", 1234).accept

gegroet,
Erik V.