mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
Move where IO redirect is performed
This commit is contained in:
parent
af893f7a23
commit
960d032110
6 changed files with 68 additions and 15 deletions
11
Rakefile
11
Rakefile
|
@ -104,3 +104,14 @@ if IS_JRUBY
|
|||
else
|
||||
task :test => [:compile]
|
||||
end
|
||||
|
||||
namespace :test do
|
||||
desc "Run the integration tests"
|
||||
task :integration do
|
||||
sh "cd test/shell; sh run.sh"
|
||||
end
|
||||
|
||||
desc "Run all tests"
|
||||
task :all => [:test, "test:integration"]
|
||||
end
|
||||
|
||||
|
|
|
@ -323,6 +323,20 @@ module Puma
|
|||
log " - Goodbye!"
|
||||
end
|
||||
|
||||
def redirect_io
|
||||
stdout = @options[:redirect_stdout]
|
||||
stderr = @options[:redirect_stderr]
|
||||
append = @options[:redirect_append]
|
||||
|
||||
if stdout
|
||||
STDOUT.reopen stdout, (append ? "a" : "w")
|
||||
end
|
||||
|
||||
if stderr
|
||||
STDOUT.reopen stderr, (append ? "a" : "w")
|
||||
end
|
||||
end
|
||||
|
||||
# Parse the options, load the rackup, start the server and wait
|
||||
# for it to finish.
|
||||
#
|
||||
|
@ -349,8 +363,6 @@ module Puma
|
|||
write_pid
|
||||
write_state
|
||||
|
||||
@binder.parse @options[:binds], self
|
||||
|
||||
if clustered
|
||||
run_cluster
|
||||
else
|
||||
|
@ -362,15 +374,17 @@ module Puma
|
|||
min_t = @options[:min_threads]
|
||||
max_t = @options[:max_threads]
|
||||
|
||||
log "Puma #{Puma::Const::PUMA_VERSION} starting..."
|
||||
log "* Min threads: #{min_t}, max threads: #{max_t}"
|
||||
log "* Environment: #{ENV['RACK_ENV']}"
|
||||
|
||||
@binder.parse @options[:binds], self
|
||||
|
||||
server = Puma::Server.new @config.app, @events
|
||||
server.binder = @binder
|
||||
server.min_threads = min_t
|
||||
server.max_threads = max_t
|
||||
|
||||
log "Puma #{Puma::Const::PUMA_VERSION} starting..."
|
||||
log "* Min threads: #{min_t}, max threads: #{max_t}"
|
||||
log "* Environment: #{ENV['RACK_ENV']}"
|
||||
|
||||
@server = server
|
||||
|
||||
if str = @options[:control_url]
|
||||
|
@ -429,6 +443,8 @@ module Puma
|
|||
log "Use Ctrl-C to stop"
|
||||
end
|
||||
|
||||
redirect_io
|
||||
|
||||
begin
|
||||
server.run.join
|
||||
rescue Interrupt
|
||||
|
@ -524,6 +540,8 @@ module Puma
|
|||
log "* Min threads: #{@options[:min_threads]}, max threads: #{@options[:max_threads]}"
|
||||
log "* Environment: #{ENV['RACK_ENV']}"
|
||||
|
||||
@binder.parse @options[:binds], self
|
||||
|
||||
@master_pid = Process.pid
|
||||
|
||||
read, write = IO.pipe
|
||||
|
@ -560,12 +578,12 @@ module Puma
|
|||
|
||||
if @options[:daemon]
|
||||
Process.daemon(true)
|
||||
STDOUT.reopen "/tmp/puma.out", "a"
|
||||
STDOUT.reopen "/tmp/puma.err", "a"
|
||||
else
|
||||
log "Use Ctrl-C to stop"
|
||||
end
|
||||
|
||||
redirect_io
|
||||
|
||||
spawn_workers
|
||||
|
||||
begin
|
||||
|
|
|
@ -195,13 +195,9 @@ module Puma
|
|||
|
||||
# Redirect STDOUT and STDERR to files specified.
|
||||
def stdout_redirect(stdout=nil, stderr=nil, append=false)
|
||||
if stdout
|
||||
STDOUT.reopen stdout, (append ? "a" : "w")
|
||||
end
|
||||
|
||||
if stderr
|
||||
STDOUT.reopen stderr, (append ? "a" : "w")
|
||||
end
|
||||
@options[:redirect_stdout] = stdout
|
||||
@options[:redirect_stderr] = stderr
|
||||
@options[:redirect_append] = append
|
||||
end
|
||||
|
||||
# Configure +min+ to be the minimum number of threads to use to answer
|
||||
|
|
7
test/shell/run.sh
Normal file
7
test/shell/run.sh
Normal file
|
@ -0,0 +1,7 @@
|
|||
if ruby t1.rb > /dev/null 2>&1; then
|
||||
echo "t1 OK"
|
||||
exit 0
|
||||
else
|
||||
echo "t1 FAIL"
|
||||
exit 1
|
||||
fi
|
19
test/shell/t1.rb
Normal file
19
test/shell/t1.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
system "ruby -I../../lib ../../bin/puma -p 10102 -C t1_conf.rb ../hello.ru &"
|
||||
sleep 5
|
||||
system "curl http://localhost:10102/"
|
||||
|
||||
system "kill `cat t1-pid`"
|
||||
|
||||
sleep 1
|
||||
|
||||
log = File.read("t1-stdout")
|
||||
|
||||
File.unlink "t1-stdout"
|
||||
File.unlink "t1-pid"
|
||||
|
||||
if log =~ %r!GET / HTTP/1\.1!
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
end
|
||||
|
2
test/shell/t1_conf.rb
Normal file
2
test/shell/t1_conf.rb
Normal file
|
@ -0,0 +1,2 @@
|
|||
stdout_redirect "t1-stdout"
|
||||
pidfile "t1-pid"
|
Loading…
Add table
Reference in a new issue