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:
Clean up stale PID files when daemonizing.
chuyeow (author)
Mon Mar 03 09:59:14 -0800 2008
commit  49599e51afebd7c268cf331d1bf71e807cf9549c
tree    a6546fd3ab120cd7efa5d149af76f4cc718e9149
parent  a3967a9d06d59e54dacc0c919d038e7e59b95512
...
34
35
36
37
 
38
39
40
41
 
 
 
 
 
 
 
 
 
 
 
 
42
43
44
...
53
54
55
56
 
57
58
59
60
...
73
74
75
76
 
77
78
79
80
81
 
82
83
84
...
108
109
110
111
 
112
113
114
...
34
35
36
 
37
38
 
 
 
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
...
62
63
64
 
65
66
67
68
69
...
82
83
84
 
85
86
87
88
89
 
90
91
92
93
...
117
118
119
 
120
121
122
123
0
@@ -34,11 +34,20 @@
0
     
0
     # Turns the current script into a daemon process that detaches from the console.
0
     def daemonize
0
- raise PlatformNotSupported, 'Daemonizing not supported on Windows' if Thin.win?
0
+ raise PlatformNotSupported, 'Daemonizing is not supported on Windows' if Thin.win?
0
       raise ArgumentError, 'You must specify a pid_file to daemonize' unless @pid_file
0
- raise PidFileExist, "#{@pid_file} already exist, seems like it's already running. " +
0
- "Stop the process or delete #{@pid_file}." if File.exist?(@pid_file)
0
-
0
+
0
+ # If PID file is stale, remove it.
0
+ if File.exist?(@pid_file)
0
+ if pid && Process.running?(pid)
0
+ raise PidFileExist, "#{@pid_file} already exists, seems like it's already running (process ID: #{pid}). " +
0
+ "Stop the process or delete #{@pid_file}."
0
+ else
0
+ log ">> Deleting stale PID file #{@pid_file}"
0
+ remove_pid_file
0
+ end
0
+ end
0
+
0
       pwd = Dir.pwd # Current directory is changed during daemonization, so store it
0
       
0
       Daemonize.daemonize(File.expand_path(@log_file), name)
0
@@ -53,7 +62,7 @@
0
         remove_pid_file
0
       end
0
     end
0
-
0
+
0
     # Change privileges of the process
0
     # to the specified user and group.
0
     def change_privilege(user, group=user)
0
0
@@ -73,12 +82,12 @@
0
       log "Couldn't change user and group to #{user}:#{group}: #{e}"
0
     end
0
     
0
- # Registerer a proc to be called to restart the server.
0
+ # Registerer a proc to be called to restart the server.
0
     def on_restart(&block)
0
       @on_restart = block
0
     end
0
     
0
- # Restart the server
0
+ # Restart the server.
0
     def restart
0
       raise ArgumentError, "Can't restart, no 'on_restart' proc specified" unless @on_restart
0
       log '>> Restarting ...'
0
@@ -108,7 +117,7 @@
0
         File.delete(pid_file) if File.exist?(pid_file)
0
       end
0
       
0
- # Restart the server by sending HUP signal
0
+ # Restart the server by sending HUP signal.
0
       def restart(pid_file)
0
         send_signal('HUP', pid_file)
0
       end

Comments

    No one has commented yet.