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 use the mode
environment parameter to determine which configuration to use. 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
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.
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.
23 24 25 |
# File 'lib/runtime/server.rb', line 23 def thread @thread end |
Class Method Details
.method_missing(*args) ⇒ Object
Allows us to access the Waves::Server instance.
74 |
# File 'lib/runtime/server.rb', line 74 def method_missing(*args); @server.send(*args); end |
.run(options = {}) ⇒ Object
Start or restart the server.
70 71 72 |
# File 'lib/runtime/server.rb', line 70 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.
76 |
# File 'lib/runtime/server.rb', line 76 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
.
32 33 34 35 36 37 |
# File 'lib/runtime/server.rb', line 32 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).
26 |
# File 'lib/runtime/server.rb', line 26 def host ; [:host] || config.host ; end |
#log ⇒ Object
Start and / or access the Waves::Logger instance.
40 |
# File 'lib/runtime/server.rb', line 40 def log ; @log ||= Waves::Logger.start ; end |
#port ⇒ Object
Access the port we’re listening on (set via the configuration).
29 |
# File 'lib/runtime/server.rb', line 29 def port ; [:port] || config.port ; end |
#start ⇒ Object
Start the server.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/runtime/server.rb', line 43 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 trap('INT') { puts; stop } if @server.respond_to? :stop end end |
#stop ⇒ Object
Stop the server.
55 56 57 58 59 60 61 62 |
# File 'lib/runtime/server.rb', line 55 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.
65 |
# File 'lib/runtime/server.rb', line 65 def synchronize( &block ) ; ( @mutex ||= Mutex.new ).synchronize( &block ) ; end |