From 33a04bd677ca16d1912bfdccffb4b39131d3a675 Mon Sep 17 00:00:00 2001 From: Jim Crossley Date: Sun, 8 May 2011 19:59:15 -0400 Subject: [PATCH] Parking some pid_file experiments that I don't really like. Because jboss isn't exclusively controlled by torquespec, there's never a guarantee that the pid file corresponds to the jboss server listening on 8080. If it can't remove potential for confusion, the complexity isn't worth it. --- lib/torquespec/server.rb | 57 +++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/lib/torquespec/server.rb b/lib/torquespec/server.rb index 055d35c..79d78af 100644 --- a/lib/torquespec/server.rb +++ b/lib/torquespec/server.rb @@ -4,15 +4,21 @@ module TorqueSpec class Server def start(opts={}) - return if TorqueSpec.lazy and ready? - wait = opts[:wait].to_i - raise "JBoss is already running" if ready? - cmd = command - @process = IO.popen( cmd ) - Thread.new(@process) { |console| while(console.gets); end } - %w{ INT TERM KILL }.each { |signal| trap(signal) { stop } } - puts "#{cmd}\npid=#{@process.pid}" - wait > 0 ? wait_for_ready(wait) : @process.pid + if TorqueSpec.lazy and ready? + @pid = read_pid_file + puts "Detected running JBoss\npid=#{@pid}" + else + wait = opts[:wait].to_i + raise "JBoss is already running" if ready? + cmd = command + process = IO.popen( cmd ) + @pid = process.pid + write_pid_file + Thread.new(process) { |console| while(console.gets); end } + %w{ INT TERM KILL }.each { |signal| trap(signal) { stop } } + puts "#{cmd}\npid=#{@pid}" + wait > 0 ? wait_for_ready(wait) : @pid + end end def deploy(url) @@ -29,13 +35,14 @@ def undeploy(url) def stop if TorqueSpec.lazy - puts "JBoss still running, pid=#{@process.pid}" - elsif @process + puts "JBoss still running, pid=#{@pid}" + elsif @pid unless clean_stop - puts "Unable to shutdown JBoss cleanly, interrupting process" - Process.kill("INT", @process.pid) + puts "Unable to shutdown JBoss cleanly, interrupting process, pid=#{@pid}" + Process.kill("INT", @pid) end - @process = nil + delete_pid_file + @pid = nil puts "JBoss stopped" end end @@ -56,7 +63,7 @@ def ready? def wait_for_ready(timeout) puts "Waiting up to #{timeout}s for JBoss to boot" t0 = Time.now - while (Time.now - t0 < timeout && @process) do + while (Time.now - t0 < timeout && @pid) do if ready? puts "JBoss started in #{(Time.now - t0).to_i}s" return true @@ -68,6 +75,26 @@ def wait_for_ready(timeout) protected + def pid_file + File.join(TorqueSpec.knob_root, "pid") + end + + def write_pid_file + File.open(pid_file, "w") do |file| + file.write(@pid) + end + end + + def read_pid_file + File.open(pid_file, "r") do |file| + file.read + end if File.exist?(pid_file) + end + + def delete_pid_file + File.delete(pid_file) + end + def command java_home = java.lang::System.getProperty( 'java.home' ) "#{java_home}/bin/java -cp #{TorqueSpec.jboss_home}/bin/run.jar #{TorqueSpec.jvm_args} -Djava.endorsed.dirs=#{TorqueSpec.jboss_home}/lib/endorsed org.jboss.Main -c #{TorqueSpec.jboss_conf} -b #{TorqueSpec.host}"