stopping servers

M

Mark Volkmann

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

James Britt

Mark said:
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.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys
http://www.30secondrule.com - Building Better Tools
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top