class Percheron::Actions::Start
Attributes
cmd[R]
create[R]
create?[R]
exec_scripts[R]
needed_units[R]
unit[R]
Public Class Methods
new(unit, needed_units: [], create: true, cmd: false, exec_scripts: true)
click to toggle source
# File lib/percheron/actions/start.rb, line 6 def initialize(unit, needed_units: [], create: true, cmd: false, exec_scripts: true) @unit = unit @needed_units = needed_units @create = create @cmd = cmd @exec_scripts = exec_scripts end
Public Instance Methods
execute!()
click to toggle source
# File lib/percheron/actions/start.rb, line 14 def execute! return nil if unit.running? results = [ create! ] if unit.startable? results << start! results << execute_post_start_scripts! end results.compact.empty? ? nil : unit end
Private Instance Methods
create!()
click to toggle source
# File lib/percheron/actions/start.rb, line 33 def create! return nil unless create? Create.new(unit, cmd: cmd).execute! end
exec_scripts?()
click to toggle source
# File lib/percheron/actions/start.rb, line 29 def exec_scripts? !unit.post_start_scripts.empty? && exec_scripts end
execute_post_start_scripts!()
click to toggle source
# File lib/percheron/actions/start.rb, line 62 def execute_post_start_scripts! scripts = unit.post_start_scripts Exec.new(unit, needed_units, scripts, 'POST start').execute! if exec_scripts? end
needed_unit_names_not_running()
click to toggle source
# File lib/percheron/actions/start.rb, line 53 def needed_unit_names_not_running @needed_unit_names_not_running ||= begin unit.startable_needed_units.each_with_object([]) do |unit_tuple, all| _, unit = unit_tuple all << unit.name unless unit.running? end end end
start!()
click to toggle source
# File lib/percheron/actions/start.rb, line 38 def start! return nil if unit_running? if needed_unit_names_not_running.empty? $logger.info "Starting '#{unit.display_name}' unit" unit.container.start! else $logger.error "Cannot start '%s' unit, %s not running" % [ unit.display_name, needed_unit_names_not_running ] end end
unit_running?()
click to toggle source
# File lib/percheron/actions/start.rb, line 49 def unit_running? !unit.startable? || unit.running? end