Module: Mutx::Commands
- Defined in:
- lib/mutx/commands/bye.rb,
lib/mutx/commands/help.rb,
lib/mutx/commands/stop.rb,
lib/mutx/commands/reset.rb,
lib/mutx/commands/start.rb,
lib/mutx/commands/install.rb,
lib/mutx/commands/restart.rb,
lib/mutx/commands/reset_tasks.rb,
lib/mutx/commands/create_alert.rb
Class Method Summary collapse
- .bye ⇒ Object
- .create_alert(name) ⇒ Object
- .help ⇒ Object
- .install(origin = nil) ⇒ Object
- .reset ⇒ Object
- .reset_tasks ⇒ Object
- .restart ⇒ Object
- .start(nodemon = false) ⇒ Object
- .stop ⇒ Object
Class Method Details
.bye ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/mutx/commands/bye.rb', line 4 def self.bye Mutx::Support::Log.debug "#{self}:#{__method__}" if Mutx::Support::Log self.stop Mutx::Support::FilesCleanner.delete_mutx_folder puts "Files cleanned" puts "Bye!..." end |
.create_alert(name) ⇒ Object
4 5 6 7 8 |
# File 'lib/mutx/commands/create_alert.rb', line 4 def self.create_alert(name) begin Mutx::CreateAlert.start([name]) end end |
.help ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mutx/commands/help.rb', line 4 def self.help Mutx::Support::Log.debug "#{self}:#{__method__}" if Mutx::Support::Log puts " Mutx has some commands: - install - start - stop - restart - reset - create_alert " end |
.install(origin = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mutx/commands/install.rb', line 4 def self.install origin=nil begin Mutx::TaskRack.start([]) puts " A new folder called mutx was created. Check the configuration file under config/ folder with the name mutx.conf. You'll find some configuration values there. Take a look and set your preferences! Enjoy Mutx Thanks " puts "Now, you can run bundle install and then `mutx start` command" rescue => e puts "\n\nInstallation Error: #{e}\n\n".red end end |
.reset ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mutx/commands/reset.rb', line 4 def self.reset Mutx::Support::Log.debug "#{self}:#{__method__}" if Mutx::Support::Log begin Mutx::Support::Configuration.get Mutx::Database::MongoConnector.new(Mutx::Support::Configuration.db_connection_data) print "\nCleanning database..." Mutx::Database::MongoConnector.drop_collections print "Done!\n\n" print "\nCleanning project..." Mutx::Support::FilesCleanner.start! print "Done!\n\n" ##Mutx::Database::MongoConnector.force_close rescue => e puts "CANNOT CLEAN SYSTEM\n#{e}\n\n#{e.backtrace}" end end |
.reset_tasks ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mutx/commands/reset_tasks.rb', line 4 def self.reset_tasks Mutx::Support::Log.debug "#{self}:#{__method__}" if Mutx::Support::Log begin Mutx::Support::Configuration.get Mutx::Database::MongoConnector.new(Mutx::Support::Configuration.db_connection_data) print "\nCleanning tasks from database..." Mutx::Database::MongoConnector.drop_collections print "Done!\n\n" print "\nCleanning project..." Mutx::Support::FilesCleanner.start! print "Done!\n\n" ##Mutx::Database::MongoConnector.force_close rescue => e puts "CANNOT CLEAN SYSTEM\n#{e}\n\n#{e.backtrace}" end end |
.restart ⇒ Object
4 5 6 7 8 |
# File 'lib/mutx/commands/restart.rb', line 4 def self.restart Mutx::Support::Log.debug "#{self}:#{__method__}" if Mutx::Support::Log self.stop self.start end |
.start(nodemon = false) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/mutx/commands/start.rb', line 4 def self.start nodemon=false # Check if mutx is already running, proceed to start if not pids = (Mutx::Support::Processes.sidekiq_pids).concat(Mutx::Support::Processes.mutx_pids) if pids.size > 0 puts "It seems that MuTX is already running. pids found #{pids}" puts "Please, run `mutx stop` command before starting MuTX" else Mutx::Support::Log.start Mutx::Support::Log.debug "Starting Mutx" if Mutx::Support::Log begin Mutx::Support::Configuration.new Mutx::Support::Log.debug "Starting...\n\n#{Mutx::Support::Logo.logo}" if Mutx::Support::Log Mutx::Support::Log.debug "Checking config.ru file existance" if Mutx::Support::Log raise "ERROR --- mutx/config.ru file was not found.`" unless File.exist?("#{Dir.pwd}/mutx/config.ru") Mutx::Support::Log.debug "Checking unicorn.rb file existance" if Mutx::Support::Log raise "ERROR --- mutx/unicorn.rb file was not found." unless File.exist?("#{Dir.pwd}/mutx/unicorn.rb") Mutx::Support::Logo.show Mutx::Support::Configuration.show_configuration_values Mutx::Support::Log.debug "Connecting to database" if Mutx::Support::Log Mutx::Database::MongoConnector.new(Mutx::Support::Configuration.db_connection_data) Mutx::Support::Log.debug "Loading doc" if Mutx::Support::Log Mutx::Support::Documentation.load_documentation if Mutx::Support::Configuration.headless? Mutx::Support::Log.debug "Headless mode: ON - Checking xvfb existance" if Mutx::Support::Log begin res = Mutx::Support::Console.execute "xvfb-run" if res.include? "sudo apt-get install xvfb" puts "You have configured headless mode but xvfb package is not installed on your system. Please, install xvfb package if you want to run browsers in headless mode or set headless active value as false if you do not use browser in your tests." return end rescue # if mac, show option puts "Not Ubuntu OS...xvfb will not work" end end puts "\n" Mutx::Support::Log.debug "Cleanning old mutx report files" if Mutx::Support::Log Mutx::Support::FilesCleanner.delete_mutx_reports() Mutx::Support::Log.debug "Old mutx report files cleanned" if Mutx::Support::Log Mutx::Support::Log.debug "Cleanning old mutx console files" if Mutx::Support::Log Mutx::Support::FilesCleanner.delete_console_outputs_files() Mutx::Support::Log.debug "Old mutx console files cleanned" if Mutx::Support::Log Mutx::Support::Log.debug "Clearing mutx log file" if Mutx::Support::Log Mutx::Support::FilesCleanner.clear_mutx_log Mutx::Support::Log.debug "Mutx log file cleanned" if Mutx::Support::Log Mutx::Support::Log.debug "Clearing sidekiq log file" if Mutx::Support::Log Mutx::Support::FilesCleanner.clear_sidekiq_log Mutx::Support::Log.debug "Sidekiq log file cleanned" if Mutx::Support::Log # Force results to reset or finished status Mutx::Support::Log.debug "Reseting defunct executions" if Mutx::Support::Log Mutx::Results.reset! Mutx::Support::Log.debug "Defunct execution reseted" if Mutx::Support::Log puts "\n* Results: Reseted".green mutx_arg = "-D" unless nodemon Mutx::Database::MongoConnector.update_last_exec_time #Update of last_exec_time on all task #before workers start Mutx::Support::Log.debug "Starting Sidekiq" if Mutx::Support::Log Mutx::BackgroundJobs::Sidekiq.start Mutx::Support::Log.debug "Sidekiq Started" if Mutx::Support::Log # Start mutx app Mutx::Support::Log.debug "Starting Mutx" if Mutx::Support::Log Mutx::Support::Console.execute "unicorn -c #{Dir.pwd}/mutx/unicorn.rb -p #{Mutx::Support::Configuration.port} #{mutx_arg} mutx/config.ru" # Mutx::Support::Console.execute "rackup mutx/config.ru" Mutx::Support::Log.debug "Mutx started" if Mutx::Support::Log # Save all mutx pids Mutx::Support::Log.debug "Saving PIDs for Mutx" if Mutx::Support::Log File.open("#{Dir.pwd}/mutx/mutx_pids", "a"){ |f| f.write Mutx::Support::Processes.mutx_pids.join("\n")} Mutx::Support::Log.debug "Mutx PIDs saved" if Mutx::Support::Log Dir.mkdir "#{Dir.pwd}/mutx/out" unless Dir.exist? "#{Dir.pwd}/mutx/out" puts "\n\n* Mutx is succesfully Started!\n".green rescue => e Mutx::Support::Log.error "Error starting Mutx: #{e}#{e.backtrace}" if Mutx::Support::Log puts "An error ocurred while starting Mutx. See mutx log for more information.#{e} #{e.backtrace}".red end end end |
.stop ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/mutx/commands/stop.rb', line 4 def self.stop Mutx::Support::Log.debug "#{self}:#{__method__}" if Mutx::Support::Log Mutx::Support::Configuration.get # Get pids from saved file on start process if File.exist? "#{Dir.pwd}/mutx/mutx_pids" mutx_pids = IO.read("#{Dir.pwd}/mutx/mutx_pids").split("\n") # Kill all pids specified on file begin Mutx::Support::Processes.kill_all_these mutx_pids rescue end # Delete pid file File.delete("#{Dir.pwd}/mutx/mutx_pids") end if File.exist? "#{Dir.pwd}/mutx/sidekiq_pid" sidekiq_pid = IO.read("#{Dir.pwd}/mutx/sidekiq_pid").split("\n") begin Mutx::Support::Processes.kill_all_these sidekiq_pid rescue end File.delete("#{Dir.pwd}/mutx/sidekiq_pid") end if File.exist? "#{Dir.pwd}/mutx/sidekiq_cron_pid" sidekiq_cron_pid = IO.read("#{Dir.pwd}/mutx/sidekiq_cron_pid").split("\n") begin Mutx::Support::Processes.kill_all_these sidekiq_cron_pid rescue end File.delete("#{Dir.pwd}/mutx/sidekiq_cron_pid") end if File.exist? "#{Dir.pwd}/mutx/sidekiq_update_started_pid" sidekiq_update_started_pid = IO.read("#{Dir.pwd}/mutx/sidekiq_update_started_pid").split("\n") begin Mutx::Support::Processes.kill_all_these sidekiq_update_started_pid rescue end File.delete("#{Dir.pwd}/mutx/sidekiq_update_started_pid") end # Evaluates if any pid could not be killed (retry) Mutx::Support::Processes.kill_all_these(Mutx::Support::Processes.mutx_pids) if Mutx::Support::Processes.mutx_pids.empty? puts " Mutx stopped!" else puts " Could not stop Mutx. If Mutx is still running please type `mutx help` to get some help" end end |