Class: Tap::Controllers::Server
- Inherits:
-
Tap::Controller
- Object
- Tap::Controller
- Tap::Controllers::Server
- Defined in:
- lib/tap/controllers/server.rb
Overview
:startdoc::controller remotely controls and monitors server
Server provides several uris to control and monitor the server behavior. Importantly, server allows the remote shutdown of a Tap::Server if a shutdown_key is set. This makes it possible to run servers in the background and still have a shutdown handle on them.
Instance Attribute Summary
Attributes inherited from Tap::Controller
#action, #request, #response, #server
Instance Method Summary collapse
-
#config ⇒ Object
Returns the public server configurations as xml.
- #index ⇒ Object
-
#ping ⇒ Object
Returns ‘pong’.
-
#shutdown ⇒ Object
Shuts down the server.
Methods inherited from Tap::Controller
#app, call, #call, #empty_binding, inherited, #initialize, name, #persistence, #redirect, #render, #render_erb, #root, #route, #session, set, #uri
Constructor Details
This class inherits a constructor from Tap::Controller
Instance Method Details
#config ⇒ Object
Returns the public server configurations as xml.
27 28 29 30 31 32 33 34 |
# File 'lib/tap/controllers/server.rb', line 27 def config response['Content-Type'] = 'text/xml' %Q{<?xml version="1.0"?> <server> <uri>#{uri}</uri> <shutdown_key>#{shutdown_key}</shutdown_key> </server>} end |
#index ⇒ Object
16 17 18 |
# File 'lib/tap/controllers/server.rb', line 16 def index render 'index.erb' end |
#ping ⇒ Object
Returns ‘pong’.
21 22 23 24 |
# File 'lib/tap/controllers/server.rb', line 21 def ping response['Content-Type'] = 'text/plain' "pong" end |
#shutdown ⇒ Object
Shuts down the server. Shutdown requires a shutdown key which is setup when the server is launched. If no shutdown key was setup, shutdown does nothing and responds accordingly.
39 40 41 42 43 44 45 46 47 |
# File 'lib/tap/controllers/server.rb', line 39 def shutdown if shutdown_key && request['shutdown_key'].to_i == shutdown_key # wait a second to shutdown, so the response is sent out. Thread.new {sleep 1; server.stop! } "shutdown" else "you do not have permission to shutdown this server" end end |