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
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/commands/util/components_starter.rb', line 71 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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/commands/util/components_starter.rb', line 51 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_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.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/commands/util/components_starter.rb', line 31 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
95 96 97 98 99 100 101 102 103 |
# File 'lib/commands/util/components_starter.rb', line 95 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 |