Skip to content

Commit

Permalink
Merge pull request #7 from tulios/vegas
Browse files Browse the repository at this point in the history
---

I fix some problems with JRuby. The main problem is fork method that do not
have any thing to do (jruby do not supports), so I used a thread join and I fixed my problems using with
& in execution. It just a small modification but I belive that is useful for people who
use JRuby.

Conflicts:
	lib/vegas/runner.rb
  • Loading branch information
quirkey committed Jan 23, 2012
2 parents 6dffd5f + c7fc1b6 commit 7424619
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions lib/vegas.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
begin
require 'rack'
require 'rbconfig'
rescue LoadError
require 'rubygems'
require 'rack'
Expand All @@ -10,6 +11,8 @@
module Vegas
VERSION = "0.1.8"
WINDOWS = !!(RUBY_PLATFORM =~ /(mingw|bccwin|wince|mswin32)/i)
JRUBY = !!(RbConfig::CONFIG["RUBY_INSTALL_NAME"] =~ /^jruby/i)

autoload :Runner, 'vegas/runner'

end
19 changes: 15 additions & 4 deletions lib/vegas/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def url

def start(path = nil)
logger.info "Running with Windows Settings" if WINDOWS
logger.info "Running with JRuby" if JRUBY
logger.info "Starting #{quoted_app_name}..."
begin
check_for_running(path)
Expand Down Expand Up @@ -184,14 +185,24 @@ def run!

# Adapted from Rackup
def daemonize!
if RUBY_VERSION < "1.9"
if JRUBY
# It's not a true daemon but when executed with & works like one
thread = Thread.new {daemon_execute}
thread.join

elsif RUBY_VERSION < "1.9"
logger.debug "Parent Process: #{Process.pid}"
exit!(0) if fork
logger.debug "Child Process: #{Process.pid}"
daemon_execute

else
Process.daemon(true, true)
daemon_execute
end

end

def daemon_execute
File.umask 0000
FileUtils.touch log_file
STDIN.reopen log_file
Expand All @@ -212,7 +223,7 @@ def launch!(specific_url = nil, path = nil)

def kill!
pid = File.read(pid_file)
logger.warn "Sending INT to #{pid.to_i}"
logger.warn "Sending #{kill_command} to #{pid.to_i}"
Process.kill(kill_command, pid.to_i)
rescue => e
logger.warn "pid not found at #{pid_file} : #{e}"
Expand Down Expand Up @@ -284,7 +295,7 @@ def setup_rack_handler

# If all else fails, we'll use Thin
else
Rack::Handler::Thin
JRUBY ? Rack::Handler::WEBrick : Rack::Handler::Thin
end
end

Expand Down
4 changes: 3 additions & 1 deletion test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ module TestHelper

def vegas(*args, &block)
Vegas::Runner.any_instance.stubs(:daemonize!).once
Rack::Handler::Thin.stubs(:run).once

Vegas::JRUBY ? Rack::Handler::WEBrick.stubs(:run).once : Rack::Handler::Thin.stubs(:run).once

@vegas = Vegas::Runner.new(*args, &block)
end

Expand Down
8 changes: 6 additions & 2 deletions test/test_vegas_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,12 @@
vegas(RackApp1, 'rack_app_1', {:skip_launch => true, :sessions => true})
end

it "sets default rack handler to thin" do
@vegas.rack_handler.should == Rack::Handler::Thin
it "sets default rack handler to thin when in ruby and WEBrick when in jruby" do
if Vegas::JRUBY
@vegas.rack_handler.should == Rack::Handler::WEBrick
else
@vegas.rack_handler.should == Rack::Handler::Thin
end
end
end

Expand Down

0 comments on commit 7424619

Please sign in to comment.