Class: Waves::Server
- Inherits:
-
Application
- Object
- Application
- Waves::Server
- Defined in:
- lib/runtime/server.rb
Overview
You can run the Waves::Server via the waves-server
command or via rake cluster:start
. Run waves-server --help
for options on the waves-server
command. The cluster:start
task uses the mode
environment variable to determine the active configuration. You can define port
to run on a single port, or ports
(taking an array) to run on multiple ports.
Example
Assume that ports
is set in the development configuration like this:
ports [ 2020, 2021, 2022 ]
Then you could start up instances on all three ports using:
rake cluster:start mode=development
This is the equivalent of running:
waves-server -c development -p 2020 -d
waves-server -c development -p 2021 -d
waves-server -c development -p 2022 -d
The cluster:stop
task stops all of the instances.
Instance Attribute Summary collapse
-
#thread ⇒ Object
readonly
Access the server thread.
Attributes inherited from Application
Class Method Summary collapse
-
.method_missing(*args) ⇒ Object
Allows us to access the Waves::Server instance.
-
.run(options = {}) ⇒ Object
Start or restart the server.
-
.synchronize(&block) ⇒ Object
– Probably wouldn’t need this if I added a block parameter to method_missing.
Instance Method Summary collapse
-
#daemonize ⇒ Object
Run the server as a daemon.
-
#host ⇒ Object
Access the host we’re binding to (set via the configuration).
-
#log ⇒ Object
Start and / or access the Waves::Logger instance.
-
#port ⇒ Object
Access the port we’re listening on (set via the configuration).
-
#start ⇒ Object
Start the server.
-
#stop ⇒ Object
Stop the server.
-
#synchronize(&block) ⇒ Object
Provides access to the server mutex for thread-safe operation.
- #trap(signal) ⇒ Object
Methods inherited from Application
#cache, #config, #debug?, #initialize, #mapping, #mode, #reload
Constructor Details
This class inherits a constructor from Waves::Application
Instance Attribute Details
#thread ⇒ Object (readonly)
Access the server thread.
25 26 27 |
# File 'lib/runtime/server.rb', line 25 def thread @thread end |
Class Method Details
.method_missing(*args) ⇒ Object
Allows us to access the Waves::Server instance.
84 85 86 |
# File 'lib/runtime/server.rb', line 84 def method_missing(*args) @server.send(*args) end |
.run(options = {}) ⇒ Object
Start or restart the server.
79 80 81 |
# File 'lib/runtime/server.rb', line 79 def run( ={} ) @server.stop if @server; @server = new( ); @server.start end |
.synchronize(&block) ⇒ Object
– Probably wouldn’t need this if I added a block parameter to method_missing.
89 |
# File 'lib/runtime/server.rb', line 89 def synchronize(&block) ; @server.synchronize(&block) ; end |
Instance Method Details
#daemonize ⇒ Object
Run the server as a daemon. Corresponds to the -d switch on waves-server
.
34 35 36 37 38 39 |
# File 'lib/runtime/server.rb', line 34 def daemonize pwd = Dir.pwd Daemonize.daemonize( Waves::Logger.output ) Dir.chdir(pwd) File.write( :log / "#{port}.pid", $$ ) end |
#host ⇒ Object
Access the host we’re binding to (set via the configuration).
28 |
# File 'lib/runtime/server.rb', line 28 def host ; [:host] || config.host ; end |
#log ⇒ Object
Start and / or access the Waves::Logger instance.
47 48 49 |
# File 'lib/runtime/server.rb', line 47 def log @log ||= Waves::Logger.start end |
#port ⇒ Object
Access the port we’re listening on (set via the configuration).
31 |
# File 'lib/runtime/server.rb', line 31 def port ; [:port] || config.port ; end |
#start ⇒ Object
Start the server.
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/runtime/server.rb', line 52 def start daemonize if [:daemon] start_debugger if [:debugger] log.info "** Waves Server starting on #{host}:#{port}" handler, = config.handler handler.run( config.application.to_app, ) do |server| @server = server self.trap('INT') { puts; stop } if @server.respond_to? :stop end end |
#stop ⇒ Object
Stop the server.
64 65 66 67 68 69 70 71 |
# File 'lib/runtime/server.rb', line 64 def stop log.info "** Waves Server Stopping ..." if [:daemon] pid_file = :log / $$ + '.pid'; FileUtils.rm( pid_file ) if File.exist?( pid_file ) end @server.stop log.info "** Waves Server Stopped" end |
#synchronize(&block) ⇒ Object
Provides access to the server mutex for thread-safe operation.
74 |
# File 'lib/runtime/server.rb', line 74 def synchronize( &block ) ; ( @mutex ||= Mutex.new ).synchronize( &block ) ; end |