| Class | Daemons::ApplicationGroup |
| In: |
lib/daemons/application_group.rb
|
| Parent: | Object |
| 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] |
# File lib/daemons/application_group.rb, line 26
26: def initialize(app_name, options = {})
27: @app_name = app_name
28: @options = options
29:
30: if options[:script]
31: @script = File.expand_path(options[:script])
32: end
33:
34: #@controller = controller
35: @monitor = nil
36:
37: #options = controller.options
38:
39: @multiple = options[:multiple] || false
40:
41: @dir_mode = options[:dir_mode] || :script
42: @dir = options[:dir] || ''
43:
44: @keep_pid_files = options[:keep_pid_files] || false
45:
46: #@applications = find_applications(pidfile_dir())
47: @applications = []
48: end
# File lib/daemons/application_group.rb, line 107
107: def create_monitor(an_app)
108: return if @monitor
109:
110: if options[:monitor]
111: @monitor = Monitor.new(an_app)
112:
113: @monitor.start(@applications)
114: end
115: end
# File lib/daemons/application_group.rb, line 62
62: def find_applications(dir)
63: pid_files = PidFile.find_files(dir, app_name, ! @keep_pid_files)
64:
65: #pp pid_files
66:
67: @monitor = Monitor.find(dir, app_name + '_monitor')
68:
69: pid_files.reject! {|f| f =~ /_monitor.pid$/}
70:
71: return pid_files.map {|f|
72: app = Application.new(self, {}, PidFile.existing(f))
73: setup_app(app)
74: app
75: }
76: end
# File lib/daemons/application_group.rb, line 78
78: def new_application(add_options = {})
79: if @applications.size > 0 and not @multiple
80: if options[:force]
81: @applications.delete_if {|a|
82: unless a.running?
83: a.zap
84: true
85: end
86: }
87: end
88:
89: raise RuntimeException.new('there is already one or more instance(s) of the program running') unless @applications.empty?
90: end
91:
92: app = Application.new(self, add_options)
93:
94: setup_app(app)
95:
96: @applications << app
97:
98: return app
99: end
# File lib/daemons/application_group.rb, line 58
58: def pidfile_dir
59: PidFile.dir(@dir_mode, @dir, script)
60: end
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
54: def setup
55: @applications = find_applications(pidfile_dir())
56: end
# File lib/daemons/application_group.rb, line 146
146: def show_status
147: @applications.each {|a| a.show_status}
148: end
# File lib/daemons/application_group.rb, line 117
117: def start_all
118: @monitor.stop if @monitor
119: @monitor = nil
120:
121: @applications.each {|a|
122: fork {
123: a.start
124: }
125: }
126: end