public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Set Logging module instance methods as module methods too.
Do not remove pid file when no error occured when sending signal to 
process.
macournoyer (author)
Fri Jul 18 10:36:19 -0700 2008
commit  f99bd54ab90485a5be1bdb3f86600f5fc68728a9
tree    63c8dcaf217aaa54afd7c9ae7f1c781e846cb755
parent  ebb7b0a2fb83ef4766cbf42fc7ebb6fc7caaa667
...
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
...
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
0
@@ -108,27 +108,31 @@ module Thin
0
       
0
       # Send a +signal+ to the process which PID is stored in +pid_file+.
0
       def send_signal(signal, pid_file, timeout=60)
0
- if File.file?(pid_file) && pid = open(pid_file).read
0
+ if File.file?(pid_file) && pid = File.read(pid_file)
0
           pid = pid.to_i
0
- print "Sending #{signal} signal to process #{pid} ... "
0
+ Logging.log "Sending #{signal} signal to process #{pid} ... "
0
           Process.kill(signal, pid)
0
           Timeout.timeout(timeout) do
0
             sleep 0.1 while Process.running?(pid)
0
           end
0
- puts
0
+ Logging.log ""
0
         else
0
           puts "Can't stop process, no PID found in #{pid_file}"
0
         end
0
       rescue Timeout::Error
0
- puts "Timeout! "
0
- Process.kill("KILL", pid)
0
+ Logging.log "Timeout!"
0
+ force_kill pid_file
0
       rescue Interrupt
0
- Process.kill("KILL", pid)
0
+ force_kill pid_file
0
       rescue Errno::ESRCH # No such process
0
- puts "process not found!"
0
- ensure
0
- File.delete(pid_file) if File.exist?(pid_file)
0
- end
0
+ Logging.log "process not found!"
0
+ force_kill pid_file
0
+ end
0
+
0
+ def force_kill(pid_file)
0
+ Process.kill("KILL", File.read(pid_file)) rescue nil
0
+ File.delete(pid_file) if File.exist?(pid_file) rescue nil
0
+ end
0
     end
0
     
0
     protected
...
15
16
17
18
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
49
50
...
15
16
17
 
18
19
 
20
21
22
 
23
24
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
27
28
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
0
@@ -15,35 +15,40 @@ module Thin
0
       def silent?; @silent end
0
     end
0
     
0
- # Deprecated silencer methods, those are now module methods
0
+ # Global silencer methods
0
     def silent
0
- warn "`#{self.class.name}\#silent` deprecated, use `Thin::Logging.silent?` instead"
0
       Logging.silent?
0
     end
0
     def silent=(value)
0
- warn "`#{self.class.name}\#silent=` deprecated, use `Thin::Logging.silent = #{value}` instead"
0
       Logging.silent = value
0
     end
0
     
0
- protected
0
- # Log a message to the console
0
- def log(msg)
0
- puts msg unless Logging.silent?
0
- end
0
-
0
- # Log a message to the console if tracing is activated
0
- def trace(msg=nil)
0
- log msg || yield if Logging.trace?
0
- end
0
-
0
- # Log a message to the console if debugging is activated
0
- def debug(msg=nil)
0
- log msg || yield if Logging.debug?
0
- end
0
-
0
- # Log an error backtrace if debugging is activated
0
- def log_error(e=$!)
0
- debug "#{e}\n\t" + e.backtrace.join("\n\t")
0
- end
0
+ # Log a message to the console
0
+ def log(msg)
0
+ puts msg unless Logging.silent?
0
+ end
0
+ module_function :log
0
+ public :log
0
+
0
+ # Log a message to the console if tracing is activated
0
+ def trace(msg=nil)
0
+ log msg || yield if Logging.trace?
0
+ end
0
+ module_function :trace
0
+ public :trace
0
+
0
+ # Log a message to the console if debugging is activated
0
+ def debug(msg=nil)
0
+ log msg || yield if Logging.debug?
0
+ end
0
+ module_function :debug
0
+ public :debug
0
+
0
+ # Log an error backtrace if debugging is activated
0
+ def log_error(e=$!)
0
+ debug "#{e}\n\t" + e.backtrace.join("\n\t")
0
+ end
0
+ module_function :log_error
0
+ public :log_error
0
   end
0
 end
0
\ No newline at end of file
...
144
145
146
147
148
149
150
...
144
145
146
 
147
148
149
0
@@ -144,7 +144,6 @@ module Thin
0
       debug ">> Debugging ON"
0
       trace ">> Tracing ON"
0
       
0
- log ">> Threaded mode #{@backend.threaded? ? 'ON' : 'OFF'}"
0
       log ">> Maximum connections set to #{@backend.maximum_connections}"
0
       log ">> Listening on #{@backend}, CTRL+C to stop"
0
       
...
28
29
30
31
32
 
33
34
35
36
37
38
 
 
 
 
 
39
40
41
...
28
29
30
 
 
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
0
@@ -28,14 +28,18 @@ describe Logging do
0
     @object.log 'hi'
0
   end
0
   
0
- it "should not output when silenced [deprecated]" do
0
- @object.should_receive(:warn)
0
+ it "should not output when silenced as instance method" do
0
     @object.silent = true
0
     
0
     @object.should_not_receive(:puts)
0
     @object.log 'hi'
0
   end
0
   
0
+ it "should be usable as module functions" do
0
+ Logging.silent = true
0
+ Logging.log "hi"
0
+ end
0
+
0
   after do
0
     Logging.silent = true
0
   end

Comments

    No one has commented yet.