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:
Fix hanging when restarting and no process is running in single server 
move [#67 state:resolved]
macournoyer (author)
Thu May 15 19:34:16 -0700 2008
commit  22c1acefbeeebd5693506b239768c8c776b707a5
tree    c9b6d111b60a005af5d83e5060c19949ed039b06
parent  e3249f95ea00d161a2e21834717b6f0840389b58
...
1
 
2
3
4
...
1
2
3
4
5
0
@@ -1,4 +1,5 @@
0
 == 0.8.2 ??? release
0
+ * Fix hanging when restarting and no process is running in single server move, fixes #67
0
  * Added Mack adapter [markbates]
0
  * Allow rackup .rb files by getting a conventionally named constant as the app [bmizerany]
0
 
...
83
84
85
86
87
 
 
 
88
89
90
91
92
93
 
94
95
96
 
 
 
97
98
99
...
110
111
112
113
114
115
 
 
 
 
 
116
117
118
...
83
84
85
 
 
86
87
88
89
90
91
92
93
 
94
95
 
 
96
97
98
99
100
101
...
112
113
114
 
 
 
115
116
117
118
119
120
121
122
0
@@ -83,17 +83,19 @@
0
         raise OptionRequired, :pid unless @options[:pid]
0
       
0
         tail_log(@options[:log]) do
0
- Server.kill(@options[:pid], @options[:timeout] || 60)
0
- wait_for_file :deletion, @options[:pid]
0
+ if Server.kill(@options[:pid], @options[:timeout] || 60)
0
+ wait_for_file :deletion, @options[:pid]
0
+ end
0
         end
0
       end
0
     
0
       def restart
0
         raise OptionRequired, :pid unless @options[:pid]
0
-
0
+
0
         tail_log(@options[:log]) do
0
- Server.restart(@options[:pid])
0
- wait_for_file :creation, @options[:pid]
0
+ if Server.restart(@options[:pid])
0
+ wait_for_file :creation, @options[:pid]
0
+ end
0
         end
0
       end
0
     
0
@@ -110,9 +112,11 @@
0
       protected
0
         # Wait for a pid file to either be created or deleted.
0
         def wait_for_file(state, file)
0
- case state
0
- when :creation then sleep 0.1 until File.exist?(file)
0
- when :deletion then sleep 0.1 while File.exist?(file)
0
+ Timeout.timeout(@options[:log] || 30) do
0
+ case state
0
+ when :creation then sleep 0.1 until File.exist?(file)
0
+ when :deletion then sleep 0.1 while File.exist?(file)
0
+ end
0
           end
0
         end
0
         
...
94
95
96
97
98
99
100
101
102
103
104
105
 
 
106
107
 
 
 
 
 
 
108
109
110
...
94
95
96
 
 
 
 
 
 
 
 
 
97
98
99
100
101
102
103
104
105
106
107
108
109
0
@@ -94,17 +94,16 @@
0
       # sent.
0
       def kill(pid_file, timeout=60)
0
         if pid = send_signal('QUIT', pid_file)
0
- begin
0
- Timeout.timeout(timeout) do
0
- sleep 0.1 while Process.running?(pid)
0
- end
0
- rescue Timeout::Error
0
- print "Timeout! "
0
- send_signal('KILL', pid_file)
0
- rescue Interrupt
0
- send_signal('KILL', pid_file)
0
+ Timeout.timeout(timeout) do
0
+ sleep 0.1 while Process.running?(pid)
0
           end
0
         end
0
+ rescue Timeout::Error
0
+ print "Timeout! "
0
+ send_signal('KILL', pid_file)
0
+ rescue Interrupt
0
+ send_signal('KILL', pid_file)
0
+ ensure
0
         File.delete(pid_file) if File.exist?(pid_file)
0
       end
0
       
...
174
175
176
177
 
178
179
180
...
174
175
176
 
177
178
179
180
0
@@ -174,7 +174,7 @@
0
     
0
     # +true+ if we're controlling a cluster.
0
     def cluster?
0
- @options[:only] || @options[:servers]]
0
+ @options[:only] || @options[:servers] || @options[:config]
0
     end
0
     
0
     # +true+ if we're acting a as system service.
...
133
134
135
 
 
 
 
 
 
136
137
138
...
133
134
135
136
137
138
139
140
141
142
143
144
0
@@ -133,6 +133,12 @@
0
     proc { sleep 0.1 while File.exist?(@server.pid_file) }.should take_less_then(10)
0
   end
0
   
0
+ it "should not restart when not running" do
0
+ silence_stream STDOUT do
0
+ TestServer.restart(@server.pid_file)
0
+ end
0
+ end
0
+
0
   it "should exit and raise if pid file already exist" do
0
     @pid = fork do
0
       @server.daemonize

Comments

    No one has commented yet.