Permalink
Browse files

Move where IO redirect is performed

  • Loading branch information...
1 parent af893f7 commit 960d032110d76312b7bea8d68b2bbb19be696a9d @evanphx evanphx committed Oct 13, 2012
Showing with 68 additions and 15 deletions.
  1. +11 −0 Rakefile
  2. +26 −8 lib/puma/cli.rb
  3. +3 −7 lib/puma/configuration.rb
  4. +7 −0 test/shell/run.sh
  5. +19 −0 test/shell/t1.rb
  6. +2 −0 test/shell/t1_conf.rb
View
@@ -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
+
View
@@ -323,6 +323,20 @@ def graceful_stop(server)
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 @@ def run
write_pid
write_state
- @binder.parse @options[:binds], self
-
if clustered
run_cluster
else
@@ -362,15 +374,17 @@ def run_single
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 @@ def run_single
log "Use Ctrl-C to stop"
end
+ redirect_io
+
begin
server.run.join
rescue Interrupt
@@ -524,6 +540,8 @@ def run_cluster
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 @@ def run_cluster
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 @@ def rackup(path)
# 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
View
@@ -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
View
@@ -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
+
@@ -0,0 +1,2 @@
+stdout_redirect "t1-stdout"
+pidfile "t1-pid"

0 comments on commit 960d032

Please sign in to comment.