daemons 1.0.4 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +29 -0
- data/README +30 -5
- data/Rakefile +1 -1
- data/Releases +6 -0
- data/examples/call/call.rb +3 -3
- data/examples/call/call_monitor.rb +2 -2
- data/examples/daemonize/daemonize.rb +2 -2
- data/examples/run/ctrl_crash.rb +2 -2
- data/examples/run/ctrl_exec.rb +2 -2
- data/examples/run/ctrl_exit.rb +2 -2
- data/examples/run/ctrl_monitor.rb +2 -2
- data/examples/run/ctrl_multiple.rb +2 -2
- data/examples/run/ctrl_normal.rb +2 -2
- data/examples/run/ctrl_ontop.rb +2 -2
- data/examples/run/ctrl_proc.rb +2 -2
- data/examples/run/ctrl_proc.rb.output +95 -0
- data/examples/run/ctrl_proc_simple.rb +2 -2
- data/lib/daemons.rb +1 -1
- data/lib/daemons/application.rb +16 -15
- data/lib/daemons/application_group.rb +1 -1
- data/lib/daemons/cmdline.rb +12 -1
- data/lib/daemons/daemonize.rb +5 -5
- data/lib/daemons/monitor.rb +6 -6
- data/lib/daemons/pid.rb +4 -2
- data/lib/daemons/pidfile.rb +3 -3
- metadata +4 -4
- data/examples/run/ctrl_proc.output +0 -0
data/LICENSE
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Copyright (c) 2005-2007 Thomas Uehlinger
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
This license does not apply to daemonize.rb, which is was written by
|
25
|
+
Travis Whitton und published under the following license:
|
26
|
+
|
27
|
+
The Daemonize extension module is copywrited free software by Travis Whitton
|
28
|
+
<whitton@atlantic.net>. You can redistribute it under the terms specified in
|
29
|
+
the COPYING file of the Ruby distribution.
|
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Daemons Version 1.0.
|
1
|
+
= Daemons Version 1.0.5
|
2
2
|
|
3
3
|
(See Releases for release-specific information)
|
4
4
|
|
@@ -34,7 +34,7 @@ Layout: suppose you have your self-written server <tt>myserver.rb</tt>:
|
|
34
34
|
|
35
35
|
To use <tt>myserver.rb</tt> in a production environment, you need to be able to
|
36
36
|
run <tt>myserver.rb</tt> in the _background_ (this means detach it from the console, fork it
|
37
|
-
in the background, release
|
37
|
+
in the background, release all directories and file descriptors).
|
38
38
|
|
39
39
|
Just create <tt>myserver_control.rb</tt> like this:
|
40
40
|
|
@@ -189,11 +189,36 @@ Homepage: http://physiker.ch
|
|
189
189
|
|
190
190
|
== License
|
191
191
|
|
192
|
-
|
193
|
-
|
192
|
+
Copyright (c) 2005-2007 Thomas Uehlinger
|
193
|
+
|
194
|
+
Permission is hereby granted, free of charge, to any person
|
195
|
+
obtaining a copy of this software and associated documentation
|
196
|
+
files (the "Software"), to deal in the Software without
|
197
|
+
restriction, including without limitation the rights to use,
|
198
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
199
|
+
copies of the Software, and to permit persons to whom the
|
200
|
+
Software is furnished to do so, subject to the following
|
201
|
+
conditions:
|
202
|
+
|
203
|
+
The above copyright notice and this permission notice shall be
|
204
|
+
included in all copies or substantial portions of the Software.
|
205
|
+
|
206
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
207
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
208
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
209
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
210
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
211
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
212
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
213
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
214
|
+
|
215
|
+
This license does not apply to daemonize.rb, which is was written by
|
216
|
+
Travis Whitton und published under the following license:
|
217
|
+
|
218
|
+
The Daemonize extension module is copywrited free software by Travis Whitton
|
219
|
+
<whitton@atlantic.net>. You can redistribute it under the terms specified in
|
194
220
|
the COPYING file of the Ruby distribution.
|
195
221
|
|
196
|
-
|
197
222
|
== Feedback and other resources
|
198
223
|
|
199
224
|
At http://rubyforge.org/projects/daemons.
|
data/Rakefile
CHANGED
data/Releases
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Daemons Release History
|
2
2
|
|
3
|
+
== Release 1.0.5: February 24, 2007
|
4
|
+
|
5
|
+
* Applied patch that causes daemons to use '/var/log' as logfile
|
6
|
+
directory if you use :dir_mode = :system (thanks to Han Holl).
|
7
|
+
* Daemons should now work with Ruby 1.9 (at least the basic features).
|
8
|
+
|
3
9
|
== Release 1.0.4: January 17, 2007
|
4
10
|
|
5
11
|
* Document the :log_output option (thanks to Andrew Kuklewicz).
|
data/examples/call/call.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
|
@@ -13,7 +13,7 @@ testfile = File.expand_path(__FILE__) + '.log'
|
|
13
13
|
|
14
14
|
|
15
15
|
# On the first call to <tt<call</tt>, an application group (accessible by <tt>Daemons.group</tt>)
|
16
|
-
# will be created
|
16
|
+
# will be created and the options will be kept within, so you only have to specify
|
17
17
|
# <tt>:multiple</tt> once.
|
18
18
|
#
|
19
19
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
|
data/examples/run/ctrl_crash.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
data/examples/run/ctrl_exec.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
data/examples/run/ctrl_exit.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
data/examples/run/ctrl_normal.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
data/examples/run/ctrl_ontop.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
data/examples/run/ctrl_proc.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
@@ -4,3 +4,98 @@ ping from proc!
|
|
4
4
|
ping from proc!
|
5
5
|
ping from proc!
|
6
6
|
ping from proc!
|
7
|
+
ping from proc!
|
8
|
+
ping from proc!
|
9
|
+
ping from proc!
|
10
|
+
ping from proc!
|
11
|
+
ping from proc!
|
12
|
+
ping from proc!
|
13
|
+
ping from proc!
|
14
|
+
ping from proc!
|
15
|
+
ping from proc!
|
16
|
+
ping from proc!
|
17
|
+
ping from proc!
|
18
|
+
ping from proc!
|
19
|
+
ping from proc!
|
20
|
+
ping from proc!
|
21
|
+
ping from proc!
|
22
|
+
ping from proc!
|
23
|
+
ping from proc!
|
24
|
+
ping from proc!
|
25
|
+
ping from proc!
|
26
|
+
ping from proc!
|
27
|
+
ping from proc!
|
28
|
+
ping from proc!
|
29
|
+
ping from proc!
|
30
|
+
ping from proc!
|
31
|
+
ping from proc!
|
32
|
+
ping from proc!
|
33
|
+
ping from proc!
|
34
|
+
ping from proc!
|
35
|
+
ping from proc!
|
36
|
+
ping from proc!
|
37
|
+
ping from proc!
|
38
|
+
ping from proc!
|
39
|
+
ping from proc!
|
40
|
+
ping from proc!
|
41
|
+
ping from proc!
|
42
|
+
ping from proc!
|
43
|
+
ping from proc!
|
44
|
+
ping from proc!
|
45
|
+
ping from proc!
|
46
|
+
ping from proc!
|
47
|
+
ping from proc!
|
48
|
+
ping from proc!
|
49
|
+
ping from proc!
|
50
|
+
ping from proc!
|
51
|
+
ping from proc!
|
52
|
+
ping from proc!
|
53
|
+
ping from proc!
|
54
|
+
ping from proc!
|
55
|
+
ping from proc!
|
56
|
+
ping from proc!
|
57
|
+
ping from proc!
|
58
|
+
ping from proc!
|
59
|
+
ping from proc!
|
60
|
+
ping from proc!
|
61
|
+
ping from proc!
|
62
|
+
ping from proc!
|
63
|
+
ping from proc!
|
64
|
+
ping from proc!
|
65
|
+
ping from proc!
|
66
|
+
ping from proc!
|
67
|
+
ping from proc!
|
68
|
+
ping from proc!
|
69
|
+
ping from proc!
|
70
|
+
ping from proc!
|
71
|
+
ping from proc!
|
72
|
+
ping from proc!
|
73
|
+
ping from proc!
|
74
|
+
ping from proc!
|
75
|
+
ping from proc!
|
76
|
+
ping from proc!
|
77
|
+
ping from proc!
|
78
|
+
ping from proc!
|
79
|
+
ping from proc!
|
80
|
+
ping from proc!
|
81
|
+
ping from proc!
|
82
|
+
ping from proc!
|
83
|
+
ping from proc!
|
84
|
+
ping from proc!
|
85
|
+
ping from proc!
|
86
|
+
ping from proc!
|
87
|
+
ping from proc!
|
88
|
+
ping from proc!
|
89
|
+
ping from proc!
|
90
|
+
ping from proc!
|
91
|
+
ping from proc!
|
92
|
+
ping from proc!
|
93
|
+
ping from proc!
|
94
|
+
ping from proc!
|
95
|
+
ping from proc!
|
96
|
+
ping from proc!
|
97
|
+
ping from proc!
|
98
|
+
ping from proc!
|
99
|
+
ping from proc!
|
100
|
+
ping from proc!
|
101
|
+
ping from proc!
|
@@ -1,9 +1,9 @@
|
|
1
1
|
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
|
-
if File.
|
3
|
+
if File.exist?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
5
5
|
else
|
6
|
-
require 'rubygems' rescue
|
6
|
+
begin; require 'rubygems'; rescue ::Exception; end
|
7
7
|
end
|
8
8
|
|
9
9
|
require 'daemons'
|
data/lib/daemons.rb
CHANGED
data/lib/daemons/application.rb
CHANGED
@@ -42,7 +42,8 @@ module Daemons
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def logfile
|
45
|
-
|
45
|
+
logdir = options[:dir_mode] == :system ? '/var/log' : pidfile_dir
|
46
|
+
(options[:log_output] && logdir) ? File.join(logdir, @group.app_name + '.output') : nil
|
46
47
|
end
|
47
48
|
|
48
49
|
|
@@ -63,12 +64,12 @@ module Daemons
|
|
63
64
|
# in your application!
|
64
65
|
#
|
65
66
|
at_exit {
|
66
|
-
@pid.cleanup rescue
|
67
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
67
68
|
|
68
69
|
# If the option <tt>:backtrace</tt> is used and the application did exit by itself
|
69
70
|
# create a exception log.
|
70
71
|
if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
|
71
|
-
exception_log() rescue
|
72
|
+
begin; exception_log(); rescue ::Exception; end
|
72
73
|
end
|
73
74
|
|
74
75
|
}
|
@@ -79,7 +80,7 @@ module Daemons
|
|
79
80
|
# 'TERM'.
|
80
81
|
#
|
81
82
|
trap('TERM') {
|
82
|
-
@pid.cleanup rescue
|
83
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
83
84
|
$daemons_sigterm = true
|
84
85
|
|
85
86
|
exit
|
@@ -118,12 +119,12 @@ module Daemons
|
|
118
119
|
# in your application!
|
119
120
|
#
|
120
121
|
at_exit {
|
121
|
-
@pid.cleanup rescue
|
122
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
122
123
|
|
123
124
|
# If the option <tt>:backtrace</tt> is used and the application did exit by itself
|
124
125
|
# create a exception log.
|
125
126
|
if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
|
126
|
-
exception_log() rescue
|
127
|
+
begin; exception_log(); rescue ::Exception; end
|
127
128
|
end
|
128
129
|
|
129
130
|
}
|
@@ -134,7 +135,7 @@ module Daemons
|
|
134
135
|
# 'TERM'.
|
135
136
|
#
|
136
137
|
trap('TERM') {
|
137
|
-
@pid.cleanup rescue
|
138
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
138
139
|
$daemons_sigterm = true
|
139
140
|
|
140
141
|
exit
|
@@ -161,12 +162,12 @@ module Daemons
|
|
161
162
|
# in your application!
|
162
163
|
#
|
163
164
|
at_exit {
|
164
|
-
@pid.cleanup rescue
|
165
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
165
166
|
|
166
167
|
# If the option <tt>:backtrace</tt> is used and the application did exit by itself
|
167
168
|
# create a exception log.
|
168
169
|
if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
|
169
|
-
exception_log() rescue
|
170
|
+
begin; exception_log(); rescue ::Exception; end
|
170
171
|
end
|
171
172
|
|
172
173
|
}
|
@@ -177,7 +178,7 @@ module Daemons
|
|
177
178
|
# 'TERM'.
|
178
179
|
#
|
179
180
|
trap('TERM') {
|
180
|
-
@pid.cleanup rescue
|
181
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
181
182
|
$daemons_sigterm = true
|
182
183
|
|
183
184
|
exit
|
@@ -303,7 +304,7 @@ module Daemons
|
|
303
304
|
|
304
305
|
# We try to remove the pid-files by ourselves, in case the application
|
305
306
|
# didn't clean it up.
|
306
|
-
@pid.cleanup rescue
|
307
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
307
308
|
|
308
309
|
end
|
309
310
|
|
@@ -312,13 +313,13 @@ module Daemons
|
|
312
313
|
end
|
313
314
|
|
314
315
|
def zap!
|
315
|
-
@pid.cleanup rescue
|
316
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
316
317
|
end
|
317
318
|
|
318
319
|
def show_status
|
319
320
|
running = self.running?
|
320
321
|
|
321
|
-
puts "#{self.group.app_name}: #{running ? '' : 'not '}running#{(running and @pid.
|
322
|
+
puts "#{self.group.app_name}: #{running ? '' : 'not '}running#{(running and @pid.exist?) ? ' [pid ' + @pid.pid.to_s + ']' : ''}#{(@pid.exist? and not running) ? ' (but pid-file exists: ' + @pid.pid.to_s + ')' : ''}"
|
322
323
|
end
|
323
324
|
|
324
325
|
# This function implements a (probably too simle) method to detect
|
@@ -329,7 +330,7 @@ module Daemons
|
|
329
330
|
# system.
|
330
331
|
#
|
331
332
|
def running?
|
332
|
-
if @pid.
|
333
|
+
if @pid.exist?
|
333
334
|
return Pid.running?(@pid.pid)
|
334
335
|
end
|
335
336
|
|
@@ -337,4 +338,4 @@ module Daemons
|
|
337
338
|
end
|
338
339
|
end
|
339
340
|
|
340
|
-
end
|
341
|
+
end
|
data/lib/daemons/cmdline.rb
CHANGED
@@ -50,7 +50,18 @@ module Daemons
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
|
53
|
+
begin
|
54
|
+
@usage = @opts.to_s
|
55
|
+
rescue ::Exception # work around a bug in ruby 1.9
|
56
|
+
@usage = <<END
|
57
|
+
-t, --ontop Stay on top (does not daemonize)
|
58
|
+
-f, --force Force operation
|
59
|
+
|
60
|
+
Common options:
|
61
|
+
-h, --help Show this message
|
62
|
+
--version Show version
|
63
|
+
END
|
64
|
+
end
|
54
65
|
end
|
55
66
|
|
56
67
|
|
data/lib/daemons/daemonize.rb
CHANGED
@@ -134,7 +134,7 @@ module Daemonize
|
|
134
134
|
# point them somewhere sensible
|
135
135
|
# STDOUT/STDERR should go to a logfile
|
136
136
|
|
137
|
-
STDIN.reopen "/dev/null" rescue
|
137
|
+
begin; STDIN.reopen "/dev/null"; rescue ::Exception; end
|
138
138
|
end
|
139
139
|
module_function :simulate
|
140
140
|
|
@@ -242,20 +242,20 @@ module Daemonize
|
|
242
242
|
# point them somewhere sensible
|
243
243
|
# STDOUT/STDERR should go to a logfile
|
244
244
|
def redirect_io(logfile_name)
|
245
|
-
STDIN.reopen "/dev/null" rescue
|
245
|
+
begin; STDIN.reopen "/dev/null"; rescue ::Exception; end
|
246
246
|
|
247
247
|
if logfile_name
|
248
248
|
begin
|
249
249
|
STDOUT.reopen logfile_name, "a"
|
250
250
|
STDOUT.sync = true
|
251
251
|
rescue ::Exception
|
252
|
-
STDOUT.reopen "/dev/null" rescue
|
252
|
+
begin; STDOUT.reopen "/dev/null"; rescue ::Exception; end
|
253
253
|
end
|
254
254
|
else
|
255
|
-
STDOUT.reopen "/dev/null" rescue
|
255
|
+
begin; STDOUT.reopen "/dev/null"; rescue ::Exception; end
|
256
256
|
end
|
257
257
|
|
258
|
-
STDERR.reopen STDOUT rescue
|
258
|
+
begin; STDERR.reopen STDOUT; rescue ::Exception; end
|
259
259
|
STDERR.sync = true
|
260
260
|
end
|
261
261
|
module_function :redirect_io
|
data/lib/daemons/monitor.rb
CHANGED
@@ -12,7 +12,7 @@ module Daemons
|
|
12
12
|
pid = PidFile.existing(pid)
|
13
13
|
|
14
14
|
unless PidFile.running?(pid.pid)
|
15
|
-
pid.cleanup rescue
|
15
|
+
begin; pid.cleanup; rescue ::Exception; end
|
16
16
|
return
|
17
17
|
end
|
18
18
|
|
@@ -67,7 +67,7 @@ module Daemons
|
|
67
67
|
@pid.pid = Process.pid
|
68
68
|
|
69
69
|
# at_exit {
|
70
|
-
|
70
|
+
# begin; @pid.cleanup; rescue ::Exception; end
|
71
71
|
# }
|
72
72
|
|
73
73
|
# This part is needed to remove the pid-file if the application is killed by
|
@@ -76,7 +76,7 @@ module Daemons
|
|
76
76
|
# 'TERM'.
|
77
77
|
#
|
78
78
|
# trap('TERM') {
|
79
|
-
|
79
|
+
# begin; @pid.cleanup; rescue ::Exception; end
|
80
80
|
# exit
|
81
81
|
# }
|
82
82
|
|
@@ -89,7 +89,7 @@ module Daemons
|
|
89
89
|
f.puts e.backtrace.inspect
|
90
90
|
}
|
91
91
|
ensure
|
92
|
-
@pid.cleanup rescue
|
92
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
93
93
|
exit!
|
94
94
|
end
|
95
95
|
end
|
@@ -116,11 +116,11 @@ module Daemons
|
|
116
116
|
|
117
117
|
|
118
118
|
def stop
|
119
|
-
Process.kill('TERM', @pid.pid) rescue
|
119
|
+
begin; Process.kill('TERM', @pid.pid); rescue ::Exception; end
|
120
120
|
|
121
121
|
# We try to remove the pid-files by ourselves, in case the application
|
122
122
|
# didn't clean it up.
|
123
|
-
@pid.cleanup rescue
|
123
|
+
begin; @pid.cleanup; rescue ::Exception; end
|
124
124
|
end
|
125
125
|
|
126
126
|
end
|
data/lib/daemons/pid.rb
CHANGED
@@ -22,7 +22,9 @@ module Daemons
|
|
22
22
|
break
|
23
23
|
}
|
24
24
|
ensure
|
25
|
-
ps_in.close
|
25
|
+
begin; ps_in.close; rescue ::Exception; end
|
26
|
+
begin; ps_out.close; rescue ::Exception; end
|
27
|
+
begin; ps_err.close; rescue ::Exception; end
|
26
28
|
end
|
27
29
|
|
28
30
|
# an alternative would be to use the code below, but I don't know whether this is portable
|
@@ -74,7 +76,7 @@ module Daemons
|
|
74
76
|
end
|
75
77
|
|
76
78
|
# Exists? method
|
77
|
-
def
|
79
|
+
def exist?
|
78
80
|
true
|
79
81
|
end
|
80
82
|
|
data/lib/daemons/pidfile.rb
CHANGED
@@ -64,13 +64,13 @@ module Daemons
|
|
64
64
|
File.join(@dir, "#{@progname}#{ @number or '' }.pid")
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
File.
|
67
|
+
def exist?
|
68
|
+
File.exist? filename
|
69
69
|
end
|
70
70
|
|
71
71
|
def pid=(p)
|
72
72
|
if multiple
|
73
|
-
while File.
|
73
|
+
while File.exist?(filename) and @number < 1024
|
74
74
|
@number += 1
|
75
75
|
end
|
76
76
|
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.
|
2
|
+
rubygems_version: 0.9.1
|
3
3
|
specification_version: 1
|
4
4
|
name: daemons
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.0.5
|
7
|
+
date: 2007-02-24 00:00:00 +01:00
|
8
8
|
summary: A toolkit to create and control daemons in different ways
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -33,6 +33,7 @@ files:
|
|
33
33
|
- Releases
|
34
34
|
- TODO
|
35
35
|
- README
|
36
|
+
- LICENSE
|
36
37
|
- setup.rb
|
37
38
|
- lib/daemons.rb
|
38
39
|
- lib/daemons/application.rb
|
@@ -63,7 +64,6 @@ files:
|
|
63
64
|
- examples/run/ctrl_multiple.rb
|
64
65
|
- examples/run/ctrl_normal.rb
|
65
66
|
- examples/run/ctrl_ontop.rb
|
66
|
-
- examples/run/ctrl_proc.output
|
67
67
|
- examples/run/ctrl_proc.rb
|
68
68
|
- examples/run/ctrl_proc.rb.output
|
69
69
|
- examples/run/ctrl_proc_simple.rb
|
File without changes
|