public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Doc love
macournoyer (author)
Thu Mar 06 17:27:20 -0800 2008
commit  0fd4de53ce67d782aec5bacb763c091b011c0720
tree    77528050e686145b9ca0eb431d065c7384999516
parent  2c01c5f75680d291d2ce1003bad1219b5a5079ae
0
...
9
10
11
12
13
 
 
 
 
 
14
15
16
 
17
18
19
...
27
28
29
 
 
 
 
30
31
32
...
9
10
11
 
 
12
13
14
15
16
17
 
 
18
19
20
21
...
29
30
31
32
33
34
35
36
37
38
0
@@ -9,11 +9,13 @@
0
 Which makes it, with all humility, the most secure, stable, fast and extensible Ruby web server
0
 bundled in an easy to use gem for your own pleasure.
0
 
0
-=== Installation
0
-IMPORTANT: Until EventMachine 0.11.0 is out, you have to install it from trunk or from my gem server:
0
+Site: http://code.macournoyer.com/thin/
0
+Group: http://groups.google.com/group/thin-ruby/topics
0
+Bugs: http://thin.lighthouseapp.com/projects/7212-thin
0
+Code: http://github.com/macournoyer/thin
0
+IRC: #thin on freenode
0
 
0
- sudo gem install eventmachine --source http://code.macournoyer.com
0
-
0
+=== Installation
0
 For the latest stable version:
0
 
0
  sudo gem install thin
0
@@ -27,6 +29,10 @@
0
  git clone git://github.com/macournoyer/thin.git
0
  cd thin
0
  rake install
0
+
0
+To use Thin with UNIX domain sockets you need EventMachine 0.11.0 from my gem server:
0
+
0
+ gem install eventmachine --source http://code.macournoyer.com
0
 
0
 === Usage
0
 A +thin+ script offers an easy way to start your Rails application:
...
4
5
6
 
 
 
 
 
 
7
8
9
...
28
29
30
 
31
32
33
...
37
38
39
 
40
41
42
...
46
47
48
 
49
50
51
...
55
56
57
 
 
58
59
60
...
69
70
71
 
72
73
74
...
4
5
6
7
8
9
10
11
12
13
14
15
...
34
35
36
37
38
39
40
...
44
45
46
47
48
49
50
...
54
55
56
57
58
59
60
...
64
65
66
67
68
69
70
71
...
80
81
82
83
84
85
86
0
@@ -4,6 +4,12 @@
0
     # * connection/disconnection to the server
0
     # * initialization of the connections
0
     # * manitoring of the active connections.
0
+ #
0
+ # == Implementing your own backend
0
+ # You can create your own minimal backend by inheriting this class and
0
+ # defining the +connect+ and +disconnect+ method.
0
+ # If your backend is not based on EventMachine you also need to redefine
0
+ # the +start+, +stop+, <tt>stop!</tt> and +config+ methods.
0
     class Base
0
       # Server serving the connections throught the backend
0
       attr_accessor :server
0
@@ -28,6 +34,7 @@
0
         @maximum_persistent_connections = Server::DEFAULT_MAXIMUM_PERSISTENT_CONNECTIONS
0
       end
0
       
0
+ # Start the backend and connect it.
0
       def start
0
         @stopping = false
0
         
0
@@ -37,6 +44,7 @@
0
         end
0
       end
0
       
0
+ # Stop of the backend from accepting new connections.
0
       def stop
0
         @running = false
0
         @stopping = true
0
@@ -46,6 +54,7 @@
0
         stop! if @connections.empty?
0
       end
0
       
0
+ # Force stop of the backend NOW, too bad for the current connections.
0
       def stop!
0
         @running = false
0
         @stopping = false
0
@@ -55,6 +64,8 @@
0
         close
0
       end
0
       
0
+ # Configure the backend. This method will be called before droping superuser privileges,
0
+ # so you can do crazy stuff that require godlike powers here.
0
       def config
0
         # See http://rubyeventmachine.com/pub/rdoc/files/EPOLL.html
0
         EventMachine.epoll
0
@@ -69,6 +80,7 @@
0
       def close
0
       end
0
       
0
+ # Returns +true+ if the backend is connected and running.
0
       def running?
0
         @running
0
       end
...
1
2
 
3
4
5
...
1
2
3
4
5
6
0
@@ -1,5 +1,6 @@
0
 module Thin
0
   module Backends
0
+ # Backend to act as a Swiftiply client (http://swiftiply.swiftcore.org).
0
     class SwiftiplyClient < Base
0
       attr_accessor :key
0
       
...
1
2
3
 
4
5
6
...
1
2
 
3
4
5
6
0
@@ -1,6 +1,6 @@
0
 module Thin
0
   module Backends
0
- # Connectior to act as a TCP socket server.
0
+ # Backend to act as a TCP socket server.
0
     class TcpServer < Base
0
       # Address and port on which the server is listening for connections.
0
       attr_accessor :host, :port
...
7
8
9
10
 
11
12
13
...
16
17
18
19
 
20
21
22
23
...
36
37
38
39
 
40
41
42
43
44
 
45
46
47
...
7
8
9
 
10
11
12
13
...
16
17
18
 
19
20
21
22
23
...
36
37
38
 
39
40
41
42
43
 
44
45
46
47
0
@@ -7,7 +7,7 @@
0
   class Connection < EventMachine::Connection
0
     include Logging
0
     
0
- # Rack application served by this connection.
0
+ # Rack application (adapter) served by this connection.
0
     attr_accessor :app
0
     
0
     # Backend to the server
0
@@ -16,7 +16,7 @@
0
     # Current request served by the connection
0
     attr_accessor :request
0
     
0
- # Next response sent through connection
0
+ # Next response sent through the connection
0
     attr_accessor :response
0
     
0
     # Get the connection ready to process a request.
0
0
@@ -36,12 +36,12 @@
0
     end
0
     
0
     # Called when all data was received and the request
0
- # is ready to being processed.
0
+ # is ready to be processed.
0
     def process
0
       # Add client info to the request env
0
       @request.remote_address = remote_address
0
       
0
- # Process the request
0
+ # Process the request calling the Rack adapter
0
       @response.status, @response.headers, @response.body = @app.call(@request.env)
0
       
0
       # Make the response persistent if requested by the client
...
1
2
3
 
 
4
5
6
...
27
28
29
 
30
31
32
33
34
...
35
36
37
38
 
 
39
40
41
42
43
44
 
45
46
47
 
 
48
49
50
...
64
65
66
67
 
 
68
69
70
...
1
2
3
4
5
6
7
8
...
29
30
31
32
33
34
35
36
37
...
38
39
40
 
41
42
43
44
45
46
47
48
49
50
51
 
52
53
54
55
56
...
70
71
72
 
73
74
75
76
77
0
@@ -1,6 +1,8 @@
0
 require 'yaml'
0
 
0
 module Thin
0
+ # Build and control one Thin server.
0
+ # Hey Controller pattern is not only for web apps yo!
0
   module Controllers
0
     # Raised when a mandatory option is missing to run a command.
0
     class OptionRequired < RuntimeError
0
@@ -27,6 +29,7 @@
0
       end
0
     
0
       def start
0
+ # Select proper backend
0
         server = case
0
         when @options.has_key?(:socket)
0
           Server.new(@options[:socket])
0
0
0
@@ -35,16 +38,19 @@
0
         else
0
           Server.new(@options[:address], @options[:port])
0
         end
0
-
0
+
0
+ # Set options
0
         server.pid_file = @options[:pid]
0
         server.log_file = @options[:log]
0
         server.timeout = @options[:timeout]
0
         server.maximum_connections = @options[:max_conns]
0
         server.maximum_persistent_connections = @options[:max_persistent_conns]
0
 
0
+ # Detach the process, after this line the current process returns
0
         server.daemonize if @options[:daemonize]
0
 
0
- server.config # Must be called before changing privileges since it might require superuser power.
0
+ # +config+ must be called before changing privileges since it might require superuser power.
0
+ server.config
0
         
0
         server.change_privilege @options[:user], @options[:group] if @options[:user] && @options[:group]
0
 
0
@@ -64,7 +70,8 @@
0
         # If a stats URL is specified, wrap in Stats adapter
0
         server.app = Stats::Adapter.new(server.app, @options[:stats]) if @options[:stats]
0
 
0
- # Register restart procedure
0
+ # Register restart procedure which just start another process with same options,
0
+ # so that's why this is done here.
0
         server.on_restart { Command.run(:start, @options) }
0
 
0
         server.start
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@
0
       def silent?; @silent end
0
     end
0
     
0
- # Deprecated silencer methods, those are now a module methods
0
+ # Deprecated silencer methods, those are now module methods
0
     def silent
0
       warn "`#{self.class.name}\#silent` deprecated, use `Thin::Logging.silent?` instead"
0
       Logging.silent?
...
1
2
3
 
4
5
6
...
41
42
43
 
 
 
 
44
45
46
47
...
165
166
167
168
 
169
170
171
172
173
 
 
 
174
175
176
...
191
192
193
 
194
195
196
...
1
2
 
3
4
5
6
...
41
42
43
44
45
46
47
48
49
50
51
...
169
170
171
 
172
173
174
175
176
 
177
178
179
180
181
182
...
197
198
199
200
201
202
203
0
@@ -1,6 +1,6 @@
0
 module Thin
0
   # The uterly famous Thin HTTP server.
0
- # It listen for incoming request through a given backend
0
+ # It listen for incoming request through a given +backend+
0
   # and forward all request to +app+.
0
   #
0
   # == TCP server
0
@@ -41,6 +41,10 @@
0
   # end
0
   # end
0
   #
0
+ # == Controlling with signals
0
+ # * QUIT: Gracefull shutdown (see Server#stop)
0
+ # * INT and TERM: Force shutdown (see Server#stop!)
0
+ #
0
   class Server
0
     include Logging
0
     include Daemonizable
0
0
@@ -165,12 +169,14 @@
0
     end
0
     
0
     # == Configure the server
0
- # The process might need to have superuser privilege to set configure
0
+ # The process might need to have superuser privilege to configure
0
     # server with optimal options.
0
     def config
0
       @backend.config
0
     end
0
-
0
+
0
+ # Name of the server and type of backend used.
0
+ # This is also the name of the process in which Thin is running as a daemon.
0
     def name
0
       "thin server (#{@backend})"
0
     end
0
@@ -191,6 +197,7 @@
0
       end
0
       
0
       # Taken from Mongrel cgi_multipart_eof_fix
0
+ # Ruby 1.8.5 has a security bug in cgi.rb, we need to patch it.
0
       def load_cgi_multipart_eof_fix
0
         version = RUBY_VERSION.split('.').map { |i| i.to_i }
0
         

Comments

    No one has commented yet.