Forum: Ruby stopping servers

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
52a177e9dbd3e614825aabc4e45f8cd6?d=identicon&s=25 Mark Volkmann (Guest)
on 2006-01-30 04:37
(Received via mailing list)
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.
Bc6d88907ce09158581fbb9b469a35a3?d=identicon&s=25 James Britt (Guest)
on 2006-01-30 05:29
(Received via mailing list)
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.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
This topic is locked and can not be replied to.