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:
Add more doc in thin script and cluster files.
Refactor script path attribute to an instance one.
macournoyer (author)
Sat Jan 12 09:13:11 -0800 2008
commit  2b60ea8c4c40f8626847d3a67279ec3c55e0b75a
tree    567e47a5ee1faed079f1b12a4ab4350ba9330435
parent  d39a4de1448b9a7de3e311789311158f6d22252c
...
6
7
8
 
9
10
11
12
...
14
15
16
17
 
18
19
 
 
 
 
20
21
22
...
27
28
29
30
 
 
31
32
33
...
49
50
51
52
 
53
54
55
...
57
58
59
60
61
 
62
63
64
...
78
79
80
81
82
 
83
84
85
...
87
88
89
90
91
 
92
93
94
...
99
100
101
102
 
103
104
105
...
6
7
8
9
10
11
12
13
...
15
16
17
 
18
19
20
21
22
23
24
25
26
27
...
32
33
34
 
35
36
37
38
39
...
55
56
57
 
58
59
60
61
...
63
64
65
 
 
66
67
68
69
...
83
84
85
 
 
86
87
88
89
...
91
92
93
 
 
94
95
96
97
...
102
103
104
 
105
106
107
108
0
@@ -6,6 +6,7 @@
0
 
0
 COMMANDS = %w(start stop restart)
0
 
0
+# Default options values
0
 options = {
0
   :chdir => Dir.pwd,
0
   :environment => 'development',
0
0
@@ -14,9 +15,13 @@
0
   :timeout => 60,
0
   :log => 'log/thin.log',
0
   :pid => 'tmp/pids/thin.pid',
0
- :servers => 1
0
+ :servers => 1 # no cluster
0
 }
0
 
0
+# NOTE: If you add an option here make sure the key in the +options+ hash is the
0
+# same as the name of the command line option.
0
+# +option+ keys are use to build the command line to launch a cluster,
0
+# see <tt>lib/thin/cluster.rb</tt>.
0
 opts = OptionParser.new do |opts|
0
   opts.banner = "Usage: thin [options] #{COMMANDS.join('|')}"
0
 
0
@@ -27,7 +32,8 @@
0
   opts.on("-p", "--port PORT", "use PORT (default: 3000)") { |port| options[:port] = port.to_i }
0
   opts.on("-e", "--environment ENV", "Rails environment (default: development)") { |env| options[:environment] = env }
0
   opts.on("-c", "--chdir PATH", "Change to dir before starting") { |dir| options[:chdir] = File.expand_path(dir) }
0
- opts.on("-s", "--servers NUM", "Number of servers to start") { |num| options[:servers] = num.to_i }
0
+ opts.on("-s", "--servers NUM", "Number of servers to start",
0
+ "set a value >1 to start a cluster") { |num| options[:servers] = num.to_i }
0
   opts.on("-d", "--daemonize", "Run daemonized in the background") { options[:daemonize] = true }
0
   opts.on("-l", "--log FILE", "File to redirect output",
0
                               "(default: #{options[:log]})") { |file| options[:log] = file }
0
@@ -49,7 +55,7 @@
0
 end
0
 
0
 
0
-# Commands definitions
0
+# == Commands definitions
0
 
0
 def cluster?(options)
0
   options[:servers] && options[:servers] > 1
0
@@ -57,8 +63,7 @@
0
 
0
 def start(options)
0
   if cluster?(options)
0
- server = Thin::Cluster.new(options)
0
- server.start
0
+ Thin::Cluster.new(options).start
0
   else
0
     server = Thin::Server.new(options[:address], options[:port])
0
   
0
@@ -78,8 +83,7 @@
0
 
0
 def stop(options)
0
   if cluster?(options)
0
- server = Thin::Cluster.new(options)
0
- server.stop
0
+ Thin::Cluster.new(options).stop
0
   else
0
     Thin::Server.kill options[:pid], options[:timeout]
0
   end
0
@@ -87,8 +91,7 @@
0
 
0
 def restart(options)
0
   if cluster?(options)
0
- server = Thin::Cluster.new(options)
0
- server.restart
0
+ Thin::Cluster.new(options).restart
0
   else
0
     # Restart only make sense when running as a daemon
0
     options.update :daemonize => true
0
@@ -99,7 +102,7 @@
0
 end
0
 
0
 
0
-# Runs the command
0
+# == Runs the command
0
 
0
 Dir.chdir(options[:chdir])
0
 command = ARGV[0]
...
1
2
 
 
 
 
3
4
5
6
7
8
9
10
 
 
 
11
12
13
...
19
20
21
 
22
23
24
...
87
88
89
90
 
91
92
93
...
1
 
2
3
4
5
6
7
8
 
 
 
 
 
9
10
11
12
13
14
...
20
21
22
23
24
25
26
...
89
90
91
 
92
93
94
95
0
@@ -1,13 +1,14 @@
0
 module Thin
0
- # Control a set of servers. Generate start and stop commands and run them.
0
+ # Control a set of servers.
0
+ # * Generate start and stop commands and run them.
0
+ # * Inject the port number in the pid and log filenames.
0
+ # Servers are started throught the +thin+ commandline script.
0
   class Cluster
0
     include Logging
0
     
0
- class << self
0
- # Script to run
0
- attr_accessor :thin_script
0
- end
0
- self.thin_script = 'thin'
0
+ # Path to the +thin+ script used to control the servers.
0
+ # Leave this to default to use the one in the path.
0
+ attr_accessor :script
0
     
0
     # Number of servers in the cluster.
0
     attr_accessor :size
0
@@ -19,6 +20,7 @@
0
     def initialize(options)
0
       @options = options.merge(:daemonize => true)
0
       @size = @options.delete(:servers)
0
+ @script = 'thin'
0
     end
0
     
0
     def first_port; @options[:port] end
0
@@ -87,7 +89,7 @@
0
           else "--#{name.to_s.tr('_', '-')}=#{value.inspect}"
0
           end
0
         end
0
- "#{self.class.thin_script} #{cmd} #{shellified_options.compact.join(' ')}"
0
+ "#{@script} #{cmd} #{shellified_options.compact.join(' ')}"
0
       end
0
       
0
       def with_each_server
...
2
3
4
5
6
7
8
...
11
12
13
 
14
15
16
...
2
3
4
 
5
6
7
...
10
11
12
13
14
15
16
0
@@ -2,7 +2,6 @@
0
 
0
 describe Cluster do
0
   before do
0
- Thin::Cluster.thin_script = File.dirname(__FILE__) + '/../bin/thin'
0
     @cluster = Thin::Cluster.new(:chdir => File.dirname(__FILE__) + '/rails_app',
0
                                  :address => '0.0.0.0',
0
                                  :port => 3000,
0
@@ -11,6 +10,7 @@
0
                                  :log => 'thin.log',
0
                                  :pid => 'thin.pid'
0
                                 )
0
+ @cluster.script = File.dirname(__FILE__) + '/../bin/thin'
0
     @cluster.silent = true
0
   end
0
     

Comments

    No one has commented yet.