daemons 1.0.7 → 1.0.8
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 +1 -1
- data/Releases +4 -0
- data/lib/daemons.rb +1 -1
- data/lib/daemons/pid.rb +98 -83
- metadata +2 -2
data/README
CHANGED
data/Releases
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
= Daemons Release History
|
2
2
|
|
3
|
+
== Release 1.0.8: September 24, 2007
|
4
|
+
|
5
|
+
* new Pid.running? function. Checking whether a process exists by sending signal '0' (thanks to Dru Nelson).
|
6
|
+
|
3
7
|
== Release 1.0.7: July 7, 2007
|
4
8
|
|
5
9
|
* Patch to fix wrong ARGV when using :exec (in def start_exec: Kernel.exec(script(), *(@app_argv || []))) (thanks to Alex McGuire).
|
data/lib/daemons.rb
CHANGED
data/lib/daemons/pid.rb
CHANGED
@@ -1,84 +1,99 @@
|
|
1
|
-
require 'open3'
|
2
|
-
|
3
|
-
|
4
|
-
module Daemons
|
5
|
-
|
6
|
-
class Pid
|
7
|
-
|
8
|
-
def Pid.running?(pid
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
#
|
13
|
-
|
14
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
|
4
|
+
module Daemons
|
5
|
+
|
6
|
+
class Pid
|
7
|
+
|
8
|
+
def Pid.running?(pid)
|
9
|
+
# Check if process is in existence
|
10
|
+
# The simplest way to do this is to send signal '0'
|
11
|
+
# (which is a single system call) that doesn't actually
|
12
|
+
# sending a signal
|
13
|
+
begin
|
14
|
+
Process.kill(0, pid)
|
15
|
+
return true
|
16
|
+
rescue Errno::ESRCH
|
17
|
+
return true
|
18
|
+
rescue Errno::EPERM
|
19
|
+
return false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# def Pid.running?(pid, additional = nil)
|
24
|
+
# match_pid = Regexp.new("^\\s*#{pid}\\s")
|
25
|
+
# got_match = false
|
26
|
+
#
|
27
|
+
# #ps_all = IO.popen('ps ax') # the correct syntax is without a dash (-) !
|
28
|
+
# ps_in, ps_out, ps_err = Open3.popen3('ps ax') # the correct syntax is without a dash (-) !
|
29
|
+
#
|
30
|
+
# return true unless ps_out.gets
|
31
|
+
#
|
32
|
+
# begin
|
33
|
+
# ps_out.each { |psline|
|
34
|
+
# next unless psline =~ match_pid
|
35
|
+
# got_match = true
|
36
|
+
# got_match = false if additional and psline !~ /#{additional}/
|
37
|
+
# break
|
38
|
+
# }
|
39
|
+
# ensure
|
40
|
+
# begin; begin; ps_in.close; rescue ::Exception; end; ps_out.close rescue nil; ps_err.close; rescue ::Exception; end
|
41
|
+
# end
|
42
|
+
#
|
43
|
+
# # an alternative would be to use the code below, but I don't know whether this is portable
|
44
|
+
# # `ps axo pid=`.split.include? pid.to_s
|
45
|
+
#
|
46
|
+
# return got_match
|
47
|
+
# end
|
48
|
+
|
49
|
+
|
50
|
+
# Returns the directory that should be used to write the pid file to
|
51
|
+
# depending on the given mode.
|
52
|
+
#
|
53
|
+
# Some modes may require an additionaly hint, others may determine
|
54
|
+
# the directory automatically.
|
55
|
+
#
|
56
|
+
# If no valid directory is found, returns nil.
|
57
|
+
#
|
58
|
+
def Pid.dir(dir_mode, dir, script)
|
59
|
+
# nil script parameter is allowed as long as dir_mode is not :script
|
60
|
+
return nil if dir_mode == :script && script.nil?
|
61
|
+
|
62
|
+
case dir_mode
|
63
|
+
when :normal
|
64
|
+
return File.expand_path(dir)
|
65
|
+
when :script
|
66
|
+
return File.expand_path(File.join(File.dirname(script),dir))
|
67
|
+
when :system
|
68
|
+
return '/var/run'
|
69
|
+
else
|
70
|
+
raise Error.new("pid file mode '#{dir_mode}' not implemented")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Initialization method
|
75
|
+
def initialize
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
# Get method
|
80
|
+
def pid
|
81
|
+
end
|
82
|
+
|
83
|
+
# Set method
|
84
|
+
def pid=(p)
|
85
|
+
end
|
86
|
+
|
87
|
+
# Cleanup method
|
88
|
+
def cleanup
|
89
|
+
end
|
90
|
+
|
91
|
+
# Exists? method
|
92
|
+
def exist?
|
93
|
+
true
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
|
84
99
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
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.8
|
7
|
+
date: 2007-09-24 00:00:00 +02:00
|
8
8
|
summary: A toolkit to create and control daemons in different ways
|
9
9
|
require_paths:
|
10
10
|
- lib
|