daemons 1.0.7 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/README +1 -1
  2. data/Releases +4 -0
  3. data/lib/daemons.rb +1 -1
  4. data/lib/daemons/pid.rb +98 -83
  5. metadata +2 -2
data/README CHANGED
@@ -1,4 +1,4 @@
1
- = Daemons Version 1.0.7
1
+ = Daemons Version 1.0.8
2
2
 
3
3
  (See Releases for release-specific information)
4
4
 
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).
@@ -65,7 +65,7 @@ require 'daemons/controller'
65
65
  #
66
66
  module Daemons
67
67
 
68
- VERSION = "1.0.7"
68
+ VERSION = "1.0.8"
69
69
 
70
70
  require 'daemons/daemonize'
71
71
 
@@ -1,84 +1,99 @@
1
- require 'open3'
2
-
3
-
4
- module Daemons
5
-
6
- class Pid
7
-
8
- def Pid.running?(pid, additional = nil)
9
- match_pid = Regexp.new("^\\s*#{pid}\\s")
10
- got_match = false
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
- begin; begin; ps_in.close; rescue ::Exception; end; ps_out.close rescue nil; ps_err.close; rescue ::Exception; end
26
- end
27
-
28
- # an alternative would be to use the code below, but I don't know whether this is portable
29
- # `ps axo pid=`.split.include? pid.to_s
30
-
31
- return got_match
32
- end
33
-
34
-
35
- # Returns the directory that should be used to write the pid file to
36
- # depending on the given mode.
37
- #
38
- # Some modes may require an additionaly hint, others may determine
39
- # the directory automatically.
40
- #
41
- # If no valid directory is found, returns nil.
42
- #
43
- def Pid.dir(dir_mode, dir, script)
44
- # nil script parameter is allowed as long as dir_mode is not :script
45
- return nil if dir_mode == :script && script.nil?
46
-
47
- case dir_mode
48
- when :normal
49
- return File.expand_path(dir)
50
- when :script
51
- return File.expand_path(File.join(File.dirname(script),dir))
52
- when :system
53
- return '/var/run'
54
- else
55
- raise Error.new("pid file mode '#{dir_mode}' not implemented")
56
- end
57
- end
58
-
59
- # Initialization method
60
- def initialize
61
- end
62
-
63
-
64
- # Get method
65
- def pid
66
- end
67
-
68
- # Set method
69
- def pid=(p)
70
- end
71
-
72
- # Cleanup method
73
- def cleanup
74
- end
75
-
76
- # Exists? method
77
- def exist?
78
- true
79
- end
80
-
81
- end
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
7
- date: 2007-07-07 00:00:00 +02:00
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