Class: Waves::Server

Inherits:
Application show all
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

Attributes inherited from Application

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Application

#cache, #config, #debug?, #initialize, #mapping, #mode, #reload

Constructor Details

This class inherits a constructor from Waves::Application

Instance Attribute Details

#threadObject (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( options={} )
  @server.stop if @server; @server = new( options ); @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

#daemonizeObject

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

#hostObject

Access the host we’re binding to (set via the configuration).



26
# File 'lib/runtime/server.rb', line 26

def host ; options[:host] || config.host ; end

#logObject

Start and / or access the Waves::Logger instance.



40
# File 'lib/runtime/server.rb', line 40

def log ; @log ||= Waves::Logger.start ; end

#portObject

Access the port we’re listening on (set via the configuration).



29
# File 'lib/runtime/server.rb', line 29

def port ; options[:port] || config.port ; end

#startObject

Start the server.



43
44
45
46
47
48
49
50
51
52
# File 'lib/runtime/server.rb', line 43

def start
  daemonize if options[:daemon]
  start_debugger if options[:debugger]
  log.info "** Waves Server starting  on #{host}:#{port}"
  handler, options = config.handler
  handler.run( config.application.to_app, options ) do |server|
    @server = server
    trap('INT') { puts; stop } if @server.respond_to? :stop
  end
end

#stopObject

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 options[: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