Skip to content

Commit

Permalink
Parking some pid_file experiments that I don't really like.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jcrossley3 committed May 8, 2011
1 parent 1a8f990 commit 33a04bd
Showing 1 changed file with 42 additions and 15 deletions.
57 changes: 42 additions & 15 deletions lib/torquespec/server.rb
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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}"
Expand Down

0 comments on commit 33a04bd

Please sign in to comment.