Class: Drbman
- Inherits:
-
Object
- Object
- Drbman
- Defined in:
- lib/drbman/drbman.rb
Overview
Drbman is the drb manager
Synopsis
Drbman will create a project directory on a host machine, then copy a set of files to the host machine, make sure a given set of gems is installed on the host machine, then run the drb server on the host machine. Drbman also supports issuing a termination command to the drb server on the remote machine and cleaning up the project by removing the files installed onto the host machine.
Notes
Uses the Command design pattern
Instance Method Summary collapse
-
#get_object {|DRbObject| ... } ⇒ Object
Use an object from the pool.
-
#initialize(logger, choices) {|Drbman| ... } ⇒ Drbman
constructor
A new instance of Drbman.
Constructor Details
#initialize(logger, choices) {|Drbman| ... } ⇒ Drbman
Returns a new instance of Drbman.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/drbman/drbman.rb', line 35 def initialize(logger, choices, &block) @logger = logger @user_choices = choices # @hosts[machine_description] = HostMachine instance @hosts = {} @user_choices[:port] ||= 9000 @user_choices[:hosts] ||= ['localhost'] @user_choices[:gems] ||= [] @user_choices[:gems] = (@user_choices[:gems] + ['daemons']).uniq.compact raise ArgumentError.new('Missing choices[:run]') if @user_choices[:run].blank? raise ArgumentError.new('Missing choices[:hosts]') if @user_choices[:hosts].blank? raise ArgumentError.new('Missing choices[:dirs]') if @user_choices[:dirs].blank? # populate the @hosts hash. key => host machine description, value => HostMachine instance port = @user_choices[:port] @user_choices[:hosts].each do |host| host = "#{host}:#{port}" unless host =~ /\:\d+\s*$/ host_machine = HostMachine.new(host, @logger, @user_choices) @hosts[host] = host_machine if host_machine.alive? # don't use off-line host machines port += 1 end unless block.nil? begin setup @pool = DrbPool.new(@hosts, @logger) block.call(self) rescue EmptyDrbPoolError, EnvironmentError => e @logger.error { e } rescue Exception => e @logger.error { e } @logger.debug { e.backtrace.join("\n") } ensure @pool.shutdown unless @pool.nil? shutdown end end end |
Instance Method Details
#get_object {|DRbObject| ... } ⇒ Object
Use an object from the pool
81 82 83 |
# File 'lib/drbman/drbman.rb', line 81 def get_object(&block) @pool.get_object(&block) end |