Class: Daemons::ApplicationGroup
- Inherits:
-
Object
- Object
- Daemons::ApplicationGroup
- Defined in:
- lib/feed_updater/vendor/daemons/application_group.rb
Instance Attribute Summary collapse
-
#app_argv ⇒ Object
Returns the value of attribute app_argv.
-
#app_name ⇒ Object
readonly
Returns the value of attribute app_name.
-
#applications ⇒ Object
readonly
Returns the value of attribute applications.
-
#controller_argv ⇒ Object
Returns the value of attribute controller_argv.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#dir_mode ⇒ Object
Returns the value of attribute dir_mode.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
-
#multiple ⇒ Object
readonly
true if the application is supposed to run in multiple instances.
-
#options ⇒ Object
readonly
attr_reader :controller.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
- #create_monitor(an_app) ⇒ Object
- #find_applications(dir) ⇒ Object
-
#initialize(app_name, options = {}) ⇒ ApplicationGroup
constructor
A new instance of ApplicationGroup.
- #new_application(add_options = {}) ⇒ Object
- #pidfile_dir ⇒ Object
-
#setup ⇒ Object
Setup the application group.
- #show_status ⇒ Object
- #start_all ⇒ Object
- #stop_all(force = false) ⇒ Object
- #zap_all ⇒ Object
Constructor Details
#initialize(app_name, options = {}) ⇒ ApplicationGroup
Returns a new instance of ApplicationGroup.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 26 def initialize(app_name, = {}) @app_name = app_name @options = if [:script] @script = File.([:script]) end #@controller = controller @monitor = nil #options = controller.options @multiple = [:multiple] || false @dir_mode = [:dir_mode] || :script @dir = [:dir] || '' #@applications = find_applications(pidfile_dir()) @applications = [] end |
Instance Attribute Details
#app_argv ⇒ Object
Returns the value of attribute app_argv.
17 18 19 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 17 def app_argv @app_argv end |
#app_name ⇒ Object (readonly)
Returns the value of attribute app_name.
5 6 7 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 5 def app_name @app_name end |
#applications ⇒ Object (readonly)
Returns the value of attribute applications.
14 15 16 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 14 def applications @applications end |
#controller_argv ⇒ Object
Returns the value of attribute controller_argv.
16 17 18 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 16 def controller_argv @controller_argv end |
#dir ⇒ Object
Returns the value of attribute dir.
20 21 22 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 20 def dir @dir end |
#dir_mode ⇒ Object
Returns the value of attribute dir_mode.
19 20 21 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 19 def dir_mode @dir_mode end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
8 9 10 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 8 def monitor @monitor end |
#multiple ⇒ Object (readonly)
true if the application is supposed to run in multiple instances
23 24 25 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 23 def multiple @multiple end |
#options ⇒ Object (readonly)
attr_reader :controller
12 13 14 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 12 def @options end |
#script ⇒ Object (readonly)
Returns the value of attribute script.
6 7 8 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 6 def script @script end |
Instance Method Details
#create_monitor(an_app) ⇒ Object
105 106 107 108 109 110 111 112 113 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 105 def create_monitor(an_app) return if @monitor if [:monitor] @monitor = Monitor.new(an_app) @monitor.start(@applications) end end |
#find_applications(dir) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 60 def find_applications(dir) pid_files = PidFile.find_files(dir, app_name) #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 = {}) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 76 def new_application( = {}) if @applications.size > 0 and not @multiple if [: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, ) setup_app(app) @applications << app return app end |
#pidfile_dir ⇒ Object
56 57 58 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 56 def pidfile_dir PidFile.dir(@dir_mode, @dir, script) end |
#setup ⇒ Object
Setup the application group. Currently this functions calls find_applications
which finds all running instances of the application and populates the application array.
52 53 54 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 52 def setup @applications = find_applications(pidfile_dir()) end |
#show_status ⇒ Object
144 145 146 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 144 def show_status @applications.each {|a| a.show_status} end |
#start_all ⇒ Object
115 116 117 118 119 120 121 122 123 124 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 115 def start_all @monitor.stop if @monitor @monitor = nil @applications.each {|a| fork { a.start } } end |
#stop_all(force = false) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 126 def stop_all(force = false) @monitor.stop if @monitor @applications.each {|a| if force a.stop rescue nil else a.stop end } end |
#zap_all ⇒ Object
138 139 140 141 142 |
# File 'lib/feed_updater/vendor/daemons/application_group.rb', line 138 def zap_all @monitor.stop if @monitor @applications.each {|a| a.zap} end |