daemons 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +2 -2
- data/Releases +6 -0
- data/examples/run/ctrl_proc.rb.output +0 -19
- data/lib/daemons.rb +5 -2
- data/lib/daemons/daemonize.rb +17 -26
- data/lib/daemons/pid.rb +19 -10
- metadata +2 -2
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
= Daemons Version 1.0.
|
1
|
+
= Daemons Version 1.0.4
|
2
2
|
|
3
3
|
(See Releases for release-specific information)
|
4
4
|
|
@@ -184,7 +184,7 @@ The RDoc documentation is also online at http://daemons.rubyforge.org
|
|
184
184
|
|
185
185
|
== Author
|
186
186
|
|
187
|
-
Written in 2005 by Thomas Uehlinger <mailto:th.uehlinger@gmx.ch>.
|
187
|
+
Written in 2005-2007 by Thomas Uehlinger <mailto:th.uehlinger@gmx.ch>.
|
188
188
|
Homepage: http://physiker.ch
|
189
189
|
|
190
190
|
== License
|
data/Releases
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
= Daemons Release History
|
2
2
|
|
3
|
+
== Release 1.0.4: January 17, 2007
|
4
|
+
|
5
|
+
* Document the :log_output option (thanks to Andrew Kuklewicz).
|
6
|
+
* Set STDOUT.sync = true when redirecting to a logfile (thanks to Andrew Kuklewicz).
|
7
|
+
* Should now run also correctly when there is no working 'ps ax' on the system (thanks to Daniel Kehoe).
|
8
|
+
|
3
9
|
== Release 1.0.3: November 1, 2006
|
4
10
|
|
5
11
|
* Set the app_name correctly also for the monitor process (thanks to Ilya Novoselov).
|
@@ -4,22 +4,3 @@ 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!
|
data/lib/daemons.rb
CHANGED
@@ -65,7 +65,7 @@ require 'daemons/controller'
|
|
65
65
|
#
|
66
66
|
module Daemons
|
67
67
|
|
68
|
-
VERSION = "1.0.
|
68
|
+
VERSION = "1.0.4"
|
69
69
|
|
70
70
|
require 'daemons/daemonize'
|
71
71
|
|
@@ -98,13 +98,16 @@ module Daemons
|
|
98
98
|
# <tt>:dir</tt>:: Used in combination with <tt>:dir_mode</tt> (description above)
|
99
99
|
# <tt>:multiple</tt>:: Specifies whether multiple instances of the same script are allowed to run at the
|
100
100
|
# same time
|
101
|
-
# <tt>:ontop</tt>:: When given, stay on top, i.e. do not daemonize the application
|
101
|
+
# <tt>:ontop</tt>:: When given (i.e. set to true), stay on top, i.e. do not daemonize the application
|
102
102
|
# (but the pid-file and other things are written as usual)
|
103
103
|
# <tt>:mode</tt>:: <tt>:load</tt> Load the script with <tt>Kernel.load</tt>;
|
104
104
|
# <tt>:exec</tt> Execute the script file with <tt>Kernel.exec</tt>
|
105
105
|
# <tt>:backtrace</tt>:: Write a backtrace of the last exceptions to the file '[app_name].log' in the
|
106
106
|
# pid-file directory if the application exits due to an uncaught exception
|
107
107
|
# <tt>:monitor</tt>:: Monitor the programs and restart crashed instances
|
108
|
+
# <tt>:log_output</tt>:: When given (i.e. set to true), redirect both STDOUT and STDERR to a logfile
|
109
|
+
# named '[app_name].output' in the pid-file directory
|
110
|
+
#
|
108
111
|
# -----
|
109
112
|
#
|
110
113
|
# === Example:
|
data/lib/daemons/daemonize.rb
CHANGED
@@ -187,23 +187,7 @@ module Daemonize
|
|
187
187
|
end
|
188
188
|
end
|
189
189
|
|
190
|
-
|
191
|
-
# point them somewhere sensible
|
192
|
-
# STDOUT/STDERR should go to a logfile
|
193
|
-
|
194
|
-
STDIN.reopen "/dev/null" rescue nil
|
195
|
-
|
196
|
-
if logfile_name
|
197
|
-
begin
|
198
|
-
STDOUT.reopen logfile_name, "a"
|
199
|
-
rescue ::Exception
|
200
|
-
STDOUT.reopen "/dev/null" rescue nil
|
201
|
-
end
|
202
|
-
else
|
203
|
-
STDOUT.reopen "/dev/null" rescue nil
|
204
|
-
end
|
205
|
-
|
206
|
-
STDERR.reopen STDOUT rescue nil
|
190
|
+
redirect_io(logfile_name)
|
207
191
|
|
208
192
|
block.call
|
209
193
|
|
@@ -246,27 +230,34 @@ module Daemonize
|
|
246
230
|
end
|
247
231
|
end
|
248
232
|
|
249
|
-
|
250
|
-
# point them somewhere sensible
|
251
|
-
# STDOUT/STDERR should go to a logfile
|
233
|
+
redirect_io(logfile_name)
|
252
234
|
|
235
|
+
#return oldmode ? sess_id : 0 # Return value is mostly irrelevant
|
236
|
+
return sess_id
|
237
|
+
end
|
238
|
+
module_function :daemonize
|
239
|
+
|
240
|
+
|
241
|
+
# Free file descriptors and
|
242
|
+
# point them somewhere sensible
|
243
|
+
# STDOUT/STDERR should go to a logfile
|
244
|
+
def redirect_io(logfile_name)
|
253
245
|
STDIN.reopen "/dev/null" rescue nil
|
254
|
-
|
246
|
+
|
255
247
|
if logfile_name
|
256
248
|
begin
|
257
249
|
STDOUT.reopen logfile_name, "a"
|
250
|
+
STDOUT.sync = true
|
258
251
|
rescue ::Exception
|
259
252
|
STDOUT.reopen "/dev/null" rescue nil
|
260
253
|
end
|
261
254
|
else
|
262
255
|
STDOUT.reopen "/dev/null" rescue nil
|
263
256
|
end
|
264
|
-
|
265
|
-
STDERR.reopen STDOUT rescue nil
|
266
257
|
|
267
|
-
|
268
|
-
|
258
|
+
STDERR.reopen STDOUT rescue nil
|
259
|
+
STDERR.sync = true
|
269
260
|
end
|
270
|
-
module_function :
|
261
|
+
module_function :redirect_io
|
271
262
|
|
272
263
|
end
|
data/lib/daemons/pid.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
1
3
|
|
2
4
|
module Daemons
|
3
5
|
|
@@ -6,16 +8,23 @@ module Daemons
|
|
6
8
|
def Pid.running?(pid, additional = nil)
|
7
9
|
match_pid = Regexp.new("^\\s*#{pid}\\s")
|
8
10
|
got_match = false
|
9
|
-
|
10
|
-
ps_all = IO.popen(
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
|
12
|
+
#ps_all = IO.popen('ps ax') # the correct syntax is without a dash (-) !
|
13
|
+
ps_in, ps_out, ps_err = Open3.popen3('ps ax') # the correct syntax is without a dash (-) !
|
14
|
+
|
15
|
+
return true unless ps_out.gets
|
16
|
+
|
17
|
+
begin
|
18
|
+
ps_out.each { |psline|
|
19
|
+
next unless psline =~ match_pid
|
20
|
+
got_match = true
|
21
|
+
got_match = false if additional and psline !~ /#{additional}/
|
22
|
+
break
|
23
|
+
}
|
24
|
+
ensure
|
25
|
+
ps_in.close rescue nil; ps_out.close rescue nil; ps_err.close rescue nil
|
26
|
+
end
|
27
|
+
|
19
28
|
# an alternative would be to use the code below, but I don't know whether this is portable
|
20
29
|
# `ps axo pid=`.split.include? pid.to_s
|
21
30
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: daemons
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date:
|
6
|
+
version: 1.0.4
|
7
|
+
date: 2007-01-17 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
|