aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOscar Del Ben <info@oscardelben.com>2012-05-23 08:53:08 -0700
committerOscar Del Ben <info@oscardelben.com>2012-05-23 08:53:08 -0700
commit13612ae5014a98cdbb86d703b50cbdf66adbcb57 (patch)
tree88acec7643f62fa9a87d95b2a3de922d44565d53
parent05a4d8b8597b7cc70ea79b087ee491ffaaf8f504 (diff)
downloadrails-13612ae5014a98cdbb86d703b50cbdf66adbcb57.tar.gz
rails-13612ae5014a98cdbb86d703b50cbdf66adbcb57.tar.bz2
rails-13612ae5014a98cdbb86d703b50cbdf66adbcb57.zip
[Guides] Rewrite server start section
-rw-r--r--guides/source/initialization.textile31
1 files changed, 23 insertions, 8 deletions
diff --git a/guides/source/initialization.textile b/guides/source/initialization.textile
index 78790a5e3c..5ce8173e85 100644
--- a/guides/source/initialization.textile
+++ b/guides/source/initialization.textile
@@ -410,7 +410,7 @@ instance of +ActiveSupport::Logger+.
The +super+ method will call +Rack::Server.start+ which begins its definition like this:
<ruby>
-def start
+def start &blk
if options[:warn]
$-w = true
end
@@ -430,22 +430,37 @@ def start
pp wrapped_app
pp app
end
-end
-</ruby>
-In a Rails application, these options are not set at all and therefore aren't used at all. The first line of code that's executed in this method is a call to this method:
+ check_pid! if options[:pid]
-<ruby>
-wrapped_app
+ # Touch the wrapped app, so that the config.ru is loaded before
+ # daemonization (i.e. before chdir, etc).
+ wrapped_app
+
+ daemonize_app if options[:daemonize]
+
+ write_pid if options[:pid]
+
+ trap(:INT) do
+ if server.respond_to?(:shutdown)
+ server.shutdown
+ else
+ exit
+ end
+ end
+
+ server.run wrapped_app, options, &blk
+end
</ruby>
-This method calls another method:
+The interesting part for a Rails app is the last line, +server.run+. Here we encounter the +wrapped_app+ method again, which this time
+we're going to explore more.
<ruby>
@wrapped_app ||= build_app app
</ruby>
-Then the +app+ method here is defined like so:
+The +app+ method here is defined like so:
<ruby>
def app