Sha256: fc8ec85b4868df3c90ba5daaa0c3886e04e5ea89d0859b47446e923692104d5a
Contents?: true
Size: 1.48 KB
Versions: 2
Compression:
Stored size: 1.48 KB
Contents
module Freyr class ServiceGroup < Array def initialize(*args) super(*args) end def find_by_name(n) find {|s| s.name == n} end # Take care this can make a stack overflow def run return [] if empty? needs_to_run = ServiceGroup.new kill = false names = [] each do |svc| unless svc.dependencies.empty? if n = svc.dependencies.find {|s| !Service.alive?(s)} if find_by_name(n) needs_to_run << svc elsif s = Service[n].first needs_to_run << s needs_to_run << svc else puts "Can't run #{svc.name} because dependency #{n} cannot be found" kill = true end next end end Freyr.logger.debug('starting service') {svc.name} pid = svc.start! names << svc.name if pid end names += needs_to_run.run unless kill names end def stop changed_names = collect {|s| s.name if s.alive?}.compact each do |svc| Freyr.logger.debug('stopping service') {svc.name} svc.stop! end changed_names end def restart names = collect {|s| s.name} each do |s| Freyr.logger.debug('restart service') {svc.name} s.restart! names.delete(s.name) end names end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
freyr-0.3.9 | lib/freyr/service_group.rb |
freyr-0.3.8 | lib/freyr/service_group.rb |