Parent

Daemons::ApplicationGroup

Attributes

app_argv[RW]
app_name[R]
applications[R]
controller_argv[RW]
dir[RW]
dir_mode[RW]
monitor[R]
multiple[R]

true if the application is supposed to run in multiple instances

options[R]

attr_reader :controller

script[R]

Public Class Methods

new(app_name, options = {}) click to toggle source
# File lib/daemons/application_group.rb, line 26
def initialize(app_name, options = {})
  @app_name = app_name
  @options = options
  
  if options[:script]
    @script = File.expand_path(options[:script])
  end
  
  #@controller = controller
  @monitor = nil
  
  #options = controller.options
  
  @multiple = options[:multiple] || false
  
  @dir_mode = options[:dir_mode] || :script
  @dir = options[:dir] || ''
  
  @keep_pid_files = options[:keep_pid_files] || false
  
  #@applications = find_applications(pidfile_dir())
  @applications = []
end

Public Instance Methods

create_monitor(an_app) click to toggle source
# File lib/daemons/application_group.rb, line 107
def create_monitor(an_app)
  return if @monitor
  
  if options[:monitor]
    @monitor = Monitor.new(an_app)

    @monitor.start(@applications)
  end
end
find_applications(dir) click to toggle source
# File lib/daemons/application_group.rb, line 62
def find_applications(dir)
  pid_files = PidFile.find_files(dir, app_name, ! @keep_pid_files)
  
  #pp pid_files
  
  @monitor = Monitor.find(dir, app_name + '_monitor')
  
  pid_files.reject! {|f| f =~ /_monitor.pid$/}
  
  return pid_files.map {|f|
    app = Application.new(self, {}, PidFile.existing(f))
    setup_app(app)
    app
  }
end
new_application(add_options = {}) click to toggle source
# File lib/daemons/application_group.rb, line 78
def new_application(add_options = {})
  if @applications.size > 0 and not @multiple
    if options[:force]
      @applications.delete_if {|a|
        unless a.running?
          a.zap
          true
        end
      }
    end
    
    raise RuntimeException.new('there is already one or more instance(s) of the program running') unless @applications.empty?
  end
  
  app = Application.new(self, add_options)
  
  setup_app(app)
  
  @applications << app
  
  return app
end
pidfile_dir() click to toggle source
# File lib/daemons/application_group.rb, line 58
def pidfile_dir
  PidFile.dir(@dir_mode, @dir, script)
end
setup() click to toggle source

Setup the application group. Currently this functions calls find_applications which finds all running instances of the application and populates the application array.

# File lib/daemons/application_group.rb, line 54
def setup
  @applications = find_applications(pidfile_dir())
end
show_status() click to toggle source
# File lib/daemons/application_group.rb, line 146
def show_status
  @applications.each {|a| a.show_status}
end
start_all() click to toggle source
# File lib/daemons/application_group.rb, line 117
def start_all
  @monitor.stop if @monitor
  @monitor = nil
  
  @applications.each {|a| 
    fork { 
      a.start 
    } 
  }
end
stop_all(force = false) click to toggle source
# File lib/daemons/application_group.rb, line 128
def stop_all(force = false)
  @monitor.stop if @monitor
  
  @applications.each {|a| 
    if force
      begin; a.stop; rescue ::Exception; end
    else
      a.stop
    end
  }
end
zap_all() click to toggle source
# File lib/daemons/application_group.rb, line 140
def zap_all
  @monitor.stop if @monitor
  
  @applications.each {|a| a.zap}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.