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_mongo_db ⇒ boolean
Starts mongodb 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
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/commands/util/components_starter.rb', line 67 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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/commands/util/components_starter.rb', line 47 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 |
# File 'lib/commands/util/components_starter.rb', line 9 def self.start_internal_broker # Check if the broker has been started already, if it is, return return true if broker_started? # 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 so we try to start the internal broker cid = `docker run -p 1883:1883 -p 1884:80 -d -v #{Nutella.config['broker_dir']}:/db matteocollina/mosca:v2.3.0` # 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_mongo_db ⇒ boolean
Starts mongodb if it’s not started already. This operation is only necessary on mac because Ubuntu automatically installs mongo as a service and runs it.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/commands/util/components_starter.rb', line 27 def self.start_mongo_db pid_file_path = "#{Nutella.config['config_dir']}.mongo_pid" # Check if the process with pid indicated in the pidfile is alive return true if sanitize_pid_file pid_file_path # Check that mongo is not running 'unsupervised' (i.e. check port 27017), if it is, return return true unless mongo_port_free? # Mongo is not running and there is no pid file so we try to start it and create a new pid file. # Note that the pid file is created by the `startup` script, not here. pid = fork exec("mongod --config /usr/local/etc/mongod.conf > /dev/null 2>&1 & \necho $! > #{pid_file_path}") if pid.nil? # Wait a bit to give the chance to mongo 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
91 92 93 94 95 96 97 98 99 |
# File 'lib/commands/util/components_starter.rb', line 91 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 |