public
Fork of rails/rails
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/ezmobius/rails.git
Search Repo:
Implemented kill options (a la Merb).
simonjefford (author)
Sun May 04 07:42:21 -0700 2008
commit  d0728d0fd346f2282f7817c2119026cca6e83324
tree    8a901cdc3841de285dce9d146a23dc51d50654fd
parent  6ab3b4714cdc7295c6efaab918ab429584cf048d
...
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
...
53
54
55
56
57
58
59
...
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
67
68
69
 
 
 
70
0
@@ -39,6 +39,20 @@
0
   opts.on("-u", "--debugger",
0
           "Enable ruby-debugging for the server.") { options[:debugger] = true }
0
 
0
+ opts.on("-K", "--graceful PORT or all",
0
+ "Gracefully kill one rails process by port number. " +
0
+ "Use server -K all to gracefully kill all processes.") do |v|
0
+ options[:action] = :kill
0
+ options[:port] = v
0
+ end
0
+
0
+ opts.on("-k", "--kill PORT or all",
0
+ "Kill one rails process by port number. " +
0
+ "Use server -k all to kill all processes.") do |v|
0
+ options[:action] = :kill_9
0
+ options[:port] = v
0
+ end
0
+
0
   opts.separator ""
0
 
0
   opts.on("-h", "--help",
0
@@ -53,8 +67,5 @@
0
 
0
 Rails.rack_adapter = Rails::Rack::Adapter.get(options[:adapter])
0
 
0
-puts "=> Rails application starting on http://#{options[:host]}:#{options[:port]}"
0
-puts "=> Call with -d to detach"
0
-puts "=> Ctrl-C to shutdown server"
0
 Rails::Rack::Server.start(options)
...
25
26
27
 
 
 
 
28
29
30
...
25
26
27
28
29
30
31
32
33
34
0
@@ -25,6 +25,10 @@
0
           @adapters ||= Hash.new
0
           ids.each { |id| @adapters[id] = "::Rails::Rack::#{adapter_class}" }
0
         end
0
+
0
+ def run(app, options)
0
+ Rails::Rack::Server.store_pid(options[:port]) if options[:daemonize] || options[:cluster]
0
+ end
0
       end # class << self
0
       
0
     end # Adapter
...
2
3
4
5
 
6
7
8
...
13
14
15
 
16
17
18
...
2
3
4
 
5
6
7
8
...
13
14
15
16
17
18
19
0
@@ -2,7 +2,7 @@
0
 
0
 module Rails
0
   module Rack
0
- class Ebb
0
+ class Ebb < Rails::Rack::Adapter
0
       # start an Ebb server on given host and port.
0
       
0
       # ==== Parameters
0
@@ -13,6 +13,7 @@
0
       # :port<Fixnum>:: The port Ebb should bind to.
0
       # :app:: The application
0
       def self.run(app, options = {})
0
+ super
0
         Rack::Handler::Ebb.run(app, options)
0
       end
0
     end
...
2
3
4
5
 
6
7
8
9
10
11
 
12
13
14
...
2
3
4
 
5
6
7
8
9
10
11
12
13
14
15
0
@@ -2,13 +2,14 @@
0
 
0
 module Rails
0
   module Rack
0
- class FastCGI
0
+ class FastCGI < Rails::Rack::Adapter
0
       # ==== Parameters
0
       # opts<Hash>:: Options for FastCGI (see below).
0
       #
0
       # ==== Options (options)
0
       # :app<String>>:: The application name.
0
       def self.run(app, options = {})
0
+ super
0
         Rails::Rack::Handler::FastCGI.run(app, options)
0
       end
0
     end
...
3
4
5
6
 
7
8
9
...
14
15
16
 
17
18
19
...
3
4
5
 
6
7
8
9
...
14
15
16
17
18
19
20
0
@@ -3,7 +3,7 @@
0
 
0
 module Rails
0
   module Rack
0
- class Mongrel
0
+ class Mongrel < Rails::Rack::Adapter
0
       # start server on given host and port.
0
       #
0
       # ==== Parameters
0
@@ -14,6 +14,7 @@
0
       # :port<Fixnum>:: The port Mongrel should bind to.
0
       # :app<String>>:: The application name.
0
       def self.run(app, options = {})
0
+ super
0
         server = ::Mongrel::HttpServer.new(options[:host], options[:port].to_i)
0
         server.register('/', ::Rails::Rack::Handler::Mongrel.new(app))
0
         server.run.join
...
2
3
4
5
 
6
7
8
...
13
14
15
 
16
17
18
...
2
3
4
 
5
6
7
8
...
13
14
15
16
17
18
19
0
@@ -2,7 +2,7 @@
0
 
0
 module Rails
0
   module Rack
0
- class Thin
0
+ class Thin < Rails::Rack::Adapter
0
       # start a Thin server on given host and port.
0
       #
0
       # ==== Parameters
0
@@ -13,6 +13,7 @@
0
       # :port<Fixnum>:: The port Thin should bind to.
0
       # :app<String>>:: The application name.
0
       def self.run(app, options = {})
0
+ super
0
         if options[:host].include?('/')
0
           options[:host] = "#{options[:host]}-#{options[:port]}"
0
         end
...
3
4
5
6
 
7
8
9
...
14
15
16
 
17
18
19
...
3
4
5
 
6
7
8
9
...
14
15
16
17
18
19
20
0
@@ -3,7 +3,7 @@
0
 
0
 module Rails
0
   module Rack
0
- class WEBrick
0
+ class WEBrick < Rails::Rack::Adapter
0
       # start WEBrick server on given host and port.
0
       #
0
       # ==== Parameters
0
@@ -14,6 +14,7 @@
0
       # :port<Fixnum>:: The port WEBrick should bind to.
0
       # :app<String>>:: The application name.
0
       def self.run(app, options = {})
0
+ super
0
         server_options = {
0
           :Port => options[:port],
0
           :BindAddress => options[:host],
...
19
20
21
 
 
 
 
22
23
24
...
34
35
36
37
 
 
 
 
38
39
40
...
19
20
21
22
23
24
25
26
27
28
...
38
39
40
 
41
42
43
44
45
46
47
0
@@ -19,6 +19,10 @@
0
                 raise "=> Rails is already running on port: #{port}"
0
               end
0
             end
0
+ elsif options[:action] == :kill
0
+ kill(options[:port], 1)
0
+ elsif options[:action] == :kill_9
0
+ kill(options[:port])
0
           elsif options[:daemonize]
0
             unless alive?(@options[:port])
0
               remove_pid_file(@options[:port])
0
@@ -34,7 +38,10 @@
0
             app = Rails::Rack::Logger.new(app, "#{Rails.root}/log/#{@options[:environment]}.log")
0
             app = Rails::Rack::Debugger.new(app) if @options[:debugger]
0
 
0
- puts("=> Using #{Rails.rack_adapter.to_s.demodulize} Rack adapter")
0
+ puts "=> Rails application starting on http://#{options[:host]}:#{options[:port]}"
0
+ puts "=> Call with -d to detach"
0
+ puts "=> Ctrl-C to shutdown server"
0
+ puts "=> Using #{Rails.rack_adapter.to_s.demodulize} Rack adapter"
0
             Rails.rack_adapter.run(app, @options)
0
           end
0
         end

Comments

    No one has commented yet.