[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

stopping servers

Mark Volkmann

1/30/2006 3:36:00 AM

When I run servers like WEBrick or an instance of TCPServer, it's
unclear to me how to stop them, especially under Windows. Ctrl-C seems
to kill the server, but not the Ruby application in which it is
running. How can I detect that Ctrl-C has been pressed? Ctrl-Break
sends an INT signal that I can catch with trap('INT'). I'm not sure
what triggers trap('TERM'), but it's not Ctrl-C.

--
R. Mark Volkmann
Partner, Object Computing, Inc.


1 Answer

james_b

1/30/2006 4:28:00 AM

0

Mark Volkmann wrote:
> When I run servers like WEBrick or an instance of TCPServer, it's
> unclear to me how to stop them, especially under Windows. Ctrl-C seems
> to kill the server, but not the Ruby application in which it is
> running. How can I detect that Ctrl-C has been pressed? Ctrl-Break
> sends an INT signal that I can catch with trap('INT'). I'm not sure
> what triggers trap('TERM'), but it's not Ctrl-C.

My WEBrick code tends to have this line:

RUBY_PLATFORM =~ /mingw|mswin32/ ? signal = 1 : signal = "HUP"

and then, later on

# s is the server instance
trap( signal ){ s.shutdown }


I also often map a 'quit' URL so I can stop the server through a
browser or wget:

s.mount_proc('/quit') { |req, resp| s.shutdown; exit; }


--
James Britt

http://www.ru... - Ruby Help & Documentation
http://www.artima.c... - The Journal By & For Rubyists
http://www.rub... - The Ruby Store for Ruby Stuff
http://www.jame... - Playing with Better Toys
http://www.30seco... - Building Better Tools