#!/usr/bin/env ruby #LOG_FILE = '/var/log/bench_runner.log' # orig_stdout = $stdout # redirect stdout to LOG_FILE # $stdout = File.new(LOG_FILE, 'a') RHOCONNECT_PATH = ARGV[0] puts "Script #{$0} is started at #{Time.now.to_s}" begin ruby_version = `rvm current` puts "Ruby version: #{ruby_version}" puts Dir.chdir(RHOCONNECT_PATH) puts "Checking rhoconnect dependencies ..." puts `bundle update` puts puts "Installing rhoconnect ..." puts `rake install` puts Dir.chdir "bench/benchapp" #puts Dir.pwd puts "Checking bench application dependencies ..." puts `bundle update` puts # TODO: Check for another instance of bench application # log = `ps aux | grep /tmp/benchapp.pid | grep -v grep` # puts log puts "Starting bench application ..." t = Thread.new do log = `rackup -D -P /tmp/benchapp.pid -s thin config.ru` puts log end t.join =begin if ruby_version =~ /jruby/ # puts "Ruby version: #{ruby_version}" t = Thread.new do puts `jruby -S trinidad -p 9292 -r config.ru --load daemon --daemonize /tmp/benchapp.pid` end # t.join else pid = Process.fork do log = `rackup -D -P /tmp/benchapp.pid -s thin config.ru` puts log puts Process.exit(0) end Process.waitpid(pid) end =end sleep 5 raise "Error: Bench application failed to start. File /tmp/benchapp.pid does not exist." unless File.exist? '/tmp/benchapp.pid' pid = `cat /tmp/benchapp.pid` puts "Bench application is up and running with pid #{pid}" puts Dir.chdir "../" bench_errors = {} puts "Running bench scripts ..." %w[ cud_script query_only_script query_script query_md_script ].each do |script| puts "Script #{script} ..." log = `"./run_#{script}.sh"` count = 0 stats_found = nil log.each_line do |line| puts line if count <= 1 count += 1 stats_found ||= (/Statistics:/ =~ line) if stats_found puts line if line.match /err: (\d+), verification err: (\d+)$/ if $1.to_i != 0 || $2.to_i != 0 bench_errors[script] ||= [] bench_errors[script] << line end end end end puts end if not bench_errors.empty? #puts "TODO: send email" puts "The following scripts completed with errors:" bench_errors.each do |script, errors| puts "#{script}:" errors.each { |err| puts " #{err}" } end end rescue Exception => e puts e.message ensure if File.exist? '/tmp/benchapp.pid' pid = `cat /tmp/benchapp.pid` res = `kill -9 #{pid}` if pid.to_i > 0 # `kill -s SIGINT #{pid}` File.delete '/tmp/benchapp.pid' end end puts "Script #{$0} is finished at #{Time.now.to_s}" puts "" # $stdout = orig_stdout #restore stdout