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:
Restructure thin script options in 3 sections: server, daemon and cluster.

Add --only (-o) option to control only one server of a cluster.
macournoyer (author)
Sun Jan 27 11:12:55 -0800 2008
commit  3e3bb71de5fd8c3128dae9032c5195410b0f1754
tree    53dec015695c728b646d37215633adad0b67a0af
parent  e4d9619fb969c496c3fc254a997e8e9f58ab21cd
...
1
 
 
2
3
 
4
5
6
...
1
2
3
4
 
5
6
7
8
0
@@ -1,6 +1,8 @@
0
 == 0.6.2 Rambo release
0
+ * Restructure thin script options in 3 sections: server, daemon and cluster
0
+ * Add --only (-o) option to control only one server of a cluster.
0
  * Stylize stats page and make the url configurable from the thin script.
0
- * Throw error if attempting to use unix sockets on windows.
0
+ * Raise error if attempting to use unix sockets on windows.
0
  * Add example config files for http://www.tildeslash.com/monit useage.
0
    Include the example file using "include /path/to/thin/monit/file" in your monitrc file.
0
    The group settings let you do this to manage your clusters:
...
34
35
36
37
38
 
 
 
 
 
 
 
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
 
 
 
 
 
 
 
53
54
55
...
62
63
64
65
 
66
67
68
...
34
35
36
 
 
37
38
39
40
41
42
43
44
45
46
47
48
49
 
 
50
51
 
 
 
52
53
54
55
56
57
58
59
60
61
62
63
64
...
71
72
73
 
74
75
76
77
0
@@ -34,22 +34,31 @@
0
   opts.on("-S", "--socket PATH", "bind to unix domain socket") { |file| options[:socket] = file }
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",
0
- "set a value >1 to start a cluster") { |num| options[:servers] = num.to_i }
0
+ opts.on("-t", "--timeout SEC", "Request or command timeout in sec",
0
+ "(default: #{options[:timeout]})") { |sec| options[:timeout] = sec.to_i }
0
+ opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| options[:prefix] = path }
0
+ opts.on( "--stats PATH", "Mount the Stats adapter under PATH") { |path| options[:stats] = path }
0
+
0
+ opts.separator ""
0
+ opts.separator "Daemon options:"
0
+
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
   opts.on("-P", "--pid FILE", "File to store PID",
0
                               "(default: #{options[:pid]})") { |file| options[:pid] = file }
0
- opts.on("-t", "--timeout SEC", "Request or command timeout in sec",
0
- "(default: #{options[:timeout]})") { |sec| options[:timeout] = sec.to_i }
0
   opts.on("-u", "--user NAME", "User to run daemon as (use with -g)") { |user| options[:user] = user }
0
   opts.on("-g", "--group NAME", "Group to run daemon as (use with -u)") { |group| options[:group] = group }
0
- opts.on( "--prefix PATH", "Mount the app under PATH (start with /)") { |path| options[:prefix] = path }
0
- opts.on("-C", "--config PATH", "Load option from a config file") { |file| options[:config] = file }
0
- opts.on( "--stats PATH", "Mount the Stats adapter under PATH") { |path| options[:stats] = path }
0
   
0
   opts.separator ""
0
+ opts.separator "Cluster options:"
0
+
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("-o", "--only", "Send command to only one server of the cluster") { |only| options[:only] = only }
0
+ opts.on("-C", "--config PATH", "Load options from a config file") { |file| options[:config] = file }
0
+
0
+ opts.separator ""
0
   opts.separator "Common options:"
0
 
0
   opts.on_tail("-D", "--debug", "Set debbuging on") { $DEBUG = true }
0
@@ -62,7 +71,7 @@
0
 # == Utilities
0
 
0
 def cluster?(options)
0
- options[:servers] && options[:servers] > 1
0
+ options[:only] || (options[:servers] && options[:servers] > 1)
0
 end
0
 
0
 def load_options_from_config_file!(options)
...
20
21
22
 
23
24
25
...
118
119
120
121
122
 
 
 
 
 
 
123
124
125
...
20
21
22
23
24
25
26
...
119
120
121
 
 
122
123
124
125
126
127
128
129
130
0
@@ -20,6 +20,7 @@
0
     def initialize(options)
0
       @options = options.merge(:daemonize => true)
0
       @size = @options.delete(:servers)
0
+ @only = @options.delete(:only)
0
       @script = 'thin'
0
       
0
       if socket
0
@@ -118,8 +119,12 @@
0
       end
0
       
0
       def with_each_server
0
- @size.times do |n|
0
- yield socket ? n : (first_port + n)
0
+ if @only
0
+ yield @only
0
+ else
0
+ @size.times do |n|
0
+ yield socket ? n : (first_port + n)
0
+ end
0
         end
0
       end
0
       
...
106
107
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
0
@@ -106,4 +106,38 @@
0
     @cluster.stop_server 1
0
   end
0
 end
0
+
0
+describe Cluster, "controlling only one server" do
0
+ before do
0
+ @cluster = Cluster.new(:chdir => File.dirname(__FILE__) + '/rails_app',
0
+ :address => '0.0.0.0',
0
+ :port => 3000,
0
+ :servers => 3,
0
+ :timeout => 10,
0
+ :log => 'thin.log',
0
+ :pid => 'thin.pid',
0
+ :only => 3001
0
+ )
0
+ @cluster.script = File.dirname(__FILE__) + '/../bin/thin'
0
+ @cluster.silent = true
0
+ end
0
+
0
+ it 'should call only specified server' do
0
+ calls = []
0
+ @cluster.send(:with_each_server) do |n|
0
+ calls << n
0
+ end
0
+ calls.should == [3001]
0
+ end
0
+
0
+ it "should start only specified server" do
0
+ @cluster.should_receive(:`) do |with|
0
+ with.should include('thin start', '--daemonize', 'thin.3001.log', 'thin.3001.pid', '--port=3001')
0
+ with.should_not include('3000', '3002')
0
+ ''
0
+ end
0
+
0
+ @cluster.start
0
+ end
0
+end

Comments

    No one has commented yet.