Class: ComponentsStarter
- Inherits:
-
Object
- Object
- ComponentsStarter
- Defined in:
- lib/commands/util/components_starter.rb
Overview
Utility functions to start components
Class Method Summary collapse
-
.start_app_bots(app_id, app_path) ⇒ boolean
Starts the application level bots.
-
.start_framework_components ⇒ boolean
Starts all framework components.
-
.start_internal_broker ⇒ boolean
Starts the internal broker if it's not started already.
- .start_run_bots(bots_list, app_path, app_id, run_id) ⇒ Object
Class Method Details
.start_app_bots(app_id, app_path) ⇒ boolean
Starts the application level bots
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/commands/util/components_starter.rb', line 50 def self.start_app_bots( app_id, app_path ) app_bots_list = Nutella.current_app.config['app_bots'] bots_dir = "#{app_path}/bots/" # If app bots have been started already, then do nothing unless Nutella::Tmux.session_exist? Nutella::Tmux.app_bot_session_name app_id # Start all app bots in the list into a new tmux session tmux = Nutella::Tmux.new app_id, nil ComponentsList.for_each_component_in_dir bots_dir do |bot| unless app_bots_list.nil? || !app_bots_list.include?( bot ) # If there is no 'startup' script output a warning (because # startup is mandatory) and skip the bot unless File.exist?("#{bots_dir}#{bot}/startup") console.warn "Impossible to start bot #{bot}. Couldn't locate 'startup' script." next end # Create a new window in the session for this run tmux.new_app_bot_window bot end end end true end |
.start_framework_components ⇒ boolean
Starts all framework components. If order.json is present, components are started in that order.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/commands/util/components_starter.rb', line 30 def self.start_framework_components nutella_components_dir = "#{Nutella::NUTELLA_HOME}framework_components" if File.exist? "#{nutella_components_dir}/order.json" components_list = JSON.parse IO.read "#{nutella_components_dir}/order.json" else components_list = ComponentsList.components_in_dir nutella_components_dir end components_list.each do |component| if File.exist? "#{nutella_components_dir}/#{component}/startup" unless start_framework_component "#{nutella_components_dir}/#{component}" return false end end end true end |
.start_internal_broker ⇒ boolean
Starts the internal broker if it's not started already
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/commands/util/components_starter.rb', line 9 def self.start_internal_broker pid_file_path = "#{Nutella.config['broker_dir']}bin/.pid" # Check if the process with pid indicated in the pidfile is alive return true if sanitize_pid_file pid_file_path # Check that broker is not running 'unsupervised' (i.e. check port 1883), if it is, return return true unless broker_port_free? # Broker is not running and there is no pid file so we try to start # the internal broker and create a new pid file. Note that the pid file is created by # the `startup` script, not here. pid = fork exec("#{Nutella.config['broker_dir']}/startup") if pid.nil? # Wait a bit to give the chance to the broker to actually start up sleep 1 # All went well so we return true true end |
.start_run_bots(bots_list, app_path, app_id, run_id) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/commands/util/components_starter.rb', line 74 def self.start_run_bots( bots_list, app_path, app_id, run_id ) # Create a new tmux instance for this run tmux = Nutella::Tmux.new app_id, run_id # Fetch bots dir bots_dir = "#{app_path}/bots/" # Start the appropriate bots bots_list.each { |bot| start_run_level_bot(bots_dir, bot, tmux) } true end |