public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Add extra output lines to Merb::Server methods if verbose mode is on.
Mon May 12 07:06:48 -0700 2008
commit  ad8626f87845b193568ec40bb01cad443996343d
tree    5d96e2d6d08cd6e4223cd86c512148c8aee7b828
parent  304e19d16f0d12e9fc69c1435904342555b1382d
...
23
24
25
26
 
27
28
29
30
 
31
32
33
...
35
36
37
38
 
39
40
41
42
43
 
44
45
46
...
48
49
50
51
 
52
53
 
54
55
56
...
62
63
64
65
 
66
67
 
68
69
 
70
71
72
...
111
112
113
114
 
115
116
117
...
131
132
133
134
 
135
136
137
 
138
139
140
...
153
154
155
156
 
157
158
159
...
170
171
172
173
 
174
 
175
176
177
...
23
24
25
 
26
27
28
29
 
30
31
32
33
...
35
36
37
 
38
39
40
 
41
 
42
43
44
45
...
47
48
49
 
50
51
 
52
53
54
55
...
61
62
63
 
64
65
 
66
67
 
68
69
70
71
...
110
111
112
 
113
114
115
116
...
130
131
132
 
133
134
135
 
136
137
138
139
...
152
153
154
 
155
156
157
158
...
169
170
171
 
172
173
174
175
176
177
0
@@ -23,11 +23,11 @@ module Merb
0
         if @cluster
0
           @port.to_i.upto(@port.to_i + @cluster.to_i-1) do |port|
0
             pidfile = pid_file(port)
0
-            pid = IO.read(pidfile).chomp.to_i
0
+            pid = IO.read(pidfile).chomp.to_i if File.exist?(pidfile)
0
 
0
             unless alive?(port)
0
               remove_pid_file(port)
0
-              puts "Starting merb server on port #{port}, pid file: #{pidfile} and process id is #{pid}"
0
+              puts "Starting merb server on port #{port}, pid file: #{pidfile} and process id is #{pid}" if Merb::Config[:verbose]
0
               daemonize(port)
0
             else
0
               raise "Merb is already running: port is #{port}, pid file: #{pidfile}, process id is #{pid}"
0
@@ -35,12 +35,11 @@ module Merb
0
           end
0
         elsif Merb::Config[:daemonize]
0
           pidfile = pid_file(port)
0
-          pid = IO.read(pidfile).chomp.to_i
0
+          pid = IO.read(pidfile).chomp.to_i if File.exist?(pidfile)
0
 
0
           unless alive?(@port)
0
-            puts "Removing pid file #{pidfile}, port is #{port}..."
0
             remove_pid_file(@port)
0
-            puts "Daemonizing..."
0
+            puts "Daemonizing..." if Merb::Config[:verbose]
0
             daemonize(@port)
0
           else
0
             raise "Merb is already running: port is #{port}, pid file: #{pidfile}, process id is #{pid}"
0
@@ -48,9 +47,9 @@ module Merb
0
         else
0
           trap('TERM') { exit }
0
           trap('INT') { puts "\nExiting"; exit }
0
-          puts "Running bootloaders..."
0
+          puts "Running bootloaders..." if Merb::Config[:verbose]
0
           BootLoader.run
0
-          puts "Starting Rack adapter..."
0
+          puts "Starting Rack adapter..." if Merb::Config[:verbose]
0
           Merb.adapter.start(Merb::Config.to_hash)
0
         end
0
       end
0
@@ -62,11 +61,11 @@ module Merb
0
       # Boolean::
0
       #   True if Merb is running on the specified port.
0
       def alive?(port)
0
-        puts "About to check if port #{port} is alive..."
0
+        puts "About to check if port #{port} is alive..." if Merb::Config[:verbose]
0
         pidfile = pid_file(port)
0
-        puts "Pidfile is #{pidfile}..."
0
+        puts "Pidfile is #{pidfile}..." if Merb::Config[:verbose]
0
         pid = IO.read(pidfile).chomp.to_i
0
-        puts "Process id is #{pid}"
0
+        puts "Process id is #{pid}" if Merb::Config[:verbose]
0
         Process.kill(0, pid)
0
         true
0
       rescue
0
@@ -111,7 +110,7 @@ module Merb
0
       # ==== Parameters
0
       # port<~to_s>:: The port of the Merb process to daemonize.
0
       def daemonize(port)
0
-        puts "About to fork..."
0
+        puts "About to fork..." if Merb::Config[:verbose]
0
         fork do
0
           Process.setsid
0
           exit if fork
0
@@ -131,10 +130,10 @@ module Merb
0
       def change_privilege
0
         if Merb::Config[:user]
0
           if Merb::Config[:group]
0
-            puts "About to change privilege to group #{Merb::Config[:group]} and user #{Merb::Config[:user]}"
0
+            puts "About to change privilege to group #{Merb::Config[:group]} and user #{Merb::Config[:user]}" if Merb::Config[:verbose]
0
             _change_privilege(Merb::Config[:user], Merb::Config[:group])
0
           else
0
-            puts "About to change privilege to user #{Merb::Config[:user]}"
0
+            puts "About to change privilege to user #{Merb::Config[:user]}" if Merb::Config[:verbose]
0
             _change_privilege(Merb::Config[:user])
0
           end
0
         end
0
@@ -153,7 +152,7 @@ module Merb
0
       # instead of the port based PID file.
0
       def remove_pid_file(port)
0
         pidfile = pid_file(port)
0
-        puts "Removing pid file #{pidfile} (port is #{port})"
0
+        puts "Removing pid file #{pidfile} (port is #{port})..."
0
         FileUtils.rm(pidfile) if File.exist?(pidfile)
0
       end
0
 
0
@@ -170,8 +169,9 @@ module Merb
0
       # instead of the port based PID file.
0
       def store_pid(port)
0
         pidfile = pid_file(port)
0
-        puts "pid file stored at #{pidfile}"
0
+        puts "Storing pid file to #{pidfile}..."
0
         FileUtils.mkdir_p(File.dirname(pidfile)) unless File.directory?(File.dirname(pidfile))
0
+        puts "Created directory, writing process id..." if Merb::Config[:verbose]
0
         File.open(pidfile, 'w'){ |f| f.write("#{Process.pid}") }
0
       end
0
 

Comments