Class: Sunshine::ServerCluster

Inherits:
Array
  • Object
show all
Defined in:
lib/sunshine/daemons/server_cluster.rb

Overview

The ServerCluster is simply a fancy Array that conveniently forwards some method calls to each server in the array, namely: Server#setup, Server#start, Server#stop, Server#restart, Server#has_setup?, Server#status.

Instance Method Summary collapse

Constructor Details

#initialize(svr_class, count, app, options = {}) ⇒ ServerCluster

ServerClusters get initialized just like any server class with the additional svr_class (Unicorn, Thin, Mongrel) and the number of server instances you would like:

ServerCluster.new Mongrel, 3, app, :port => 5000
#=> [<# mongrel_5000 >, <# mongrel_5001 >, <# mongrel_5002 >]

ServerClusters can also be created from any Server class:

Mongrel.new_cluster 3, app, :port => 5000


23
24
25
26
27
28
29
30
# File 'lib/sunshine/daemons/server_cluster.rb', line 23

def initialize svr_class, count, app, options={}
  count.times do |num|
    port = (options[:port] || 80) + num
    name = (options[:name] || svr_class.short_name) + ".#{port}"

    self << svr_class.new(app, options.merge(:name => name, :port => port))
  end
end