daemons 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/Releases +9 -0
- data/examples/call/call.rb +1 -1
- data/examples/call/call_monitor.rb +1 -1
- data/examples/daemonize/daemonize.rb +1 -1
- data/examples/run/ctrl_crash.rb +2 -2
- data/examples/run/ctrl_exec.rb +3 -3
- 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 +1 -1
- data/examples/run/ctrl_proc.rb.output +25 -0
- data/examples/run/ctrl_proc_simple.rb +17 -0
- data/examples/run/myserver_exiting.rb +2 -2
- data/lib/daemons.rb +5 -5
- data/lib/daemons/application.rb +61 -19
- data/lib/daemons/controller.rb +1 -1
- data/lib/daemons/daemonize.rb +15 -8
- data/lib/daemons/pid.rb +74 -71
- data/lib/daemons/pidfile.rb +3 -3
- metadata +3 -2
data/README
CHANGED
data/Releases
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
= Daemons Release History
|
2
2
|
|
3
|
+
== Release 1.0.2: September 26, 2006
|
4
|
+
|
5
|
+
* Changed the 'ps -ax' call back to 'ps ax'.
|
6
|
+
* Fixed the documentation for the :normal :dir_mode.
|
7
|
+
* As a default for Daemons.run_proc, the pid file is now saved in the current directory.
|
8
|
+
* In :ontop mode for running a proc (this is equal to calling something like 'ruby ctrl_proc.rb run'),
|
9
|
+
the proc now runs directly in the calling script, not in a forked process anymore (thanks to Paul Butcher).
|
10
|
+
* Set $0 to app_name in the daemons (thanks to Ilya Novoselov).
|
11
|
+
|
3
12
|
== Release 1.0.1: August 30, 2006
|
4
13
|
|
5
14
|
* Fixed a regex for parsing the 'ps ax' system call. (thanks to Garance Alistair Drosehn)
|
data/examples/call/call.rb
CHANGED
data/examples/run/ctrl_crash.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -14,4 +14,4 @@ options = {
|
|
14
14
|
:backtrace => true
|
15
15
|
}
|
16
16
|
|
17
|
-
Daemons.run(File.join(File.
|
17
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
|
data/examples/run/ctrl_exec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -10,7 +10,7 @@ require 'daemons'
|
|
10
10
|
|
11
11
|
|
12
12
|
options = {
|
13
|
-
:
|
13
|
+
:mode => :exec
|
14
14
|
}
|
15
15
|
|
16
|
-
Daemons.run(File.join(File.
|
16
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
|
data/examples/run/ctrl_exit.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -12,4 +12,4 @@ require 'daemons'
|
|
12
12
|
options = {
|
13
13
|
}
|
14
14
|
|
15
|
-
Daemons.run(File.join(File.
|
15
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver_exiting.rb'), options)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -13,4 +13,4 @@ options = {
|
|
13
13
|
:monitor => true
|
14
14
|
}
|
15
15
|
|
16
|
-
Daemons.run(File.join(File.
|
16
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver_crashing.rb'), options)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -13,4 +13,4 @@ options = {
|
|
13
13
|
:multiple => true
|
14
14
|
}
|
15
15
|
|
16
|
-
Daemons.run(File.join(File.
|
16
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
|
data/examples/run/ctrl_normal.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -9,4 +9,4 @@ end
|
|
9
9
|
require 'daemons'
|
10
10
|
|
11
11
|
|
12
|
-
Daemons.run(File.join(File.
|
12
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'))
|
data/examples/run/ctrl_ontop.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
lib_dir = File.expand_path(File.join(File.
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
2
|
|
3
3
|
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
4
|
$LOAD_PATH.unshift lib_dir
|
@@ -13,4 +13,4 @@ options = {
|
|
13
13
|
:ontop => true
|
14
14
|
}
|
15
15
|
|
16
|
-
Daemons.run(File.join(File.
|
16
|
+
Daemons.run(File.join(File.dirname(__FILE__), 'myserver.rb'), options)
|
data/examples/run/ctrl_proc.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
ping from proc!
|
2
|
+
ping from proc!
|
3
|
+
ping from proc!
|
4
|
+
ping from proc!
|
5
|
+
ping from proc!
|
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!
|
@@ -0,0 +1,17 @@
|
|
1
|
+
lib_dir = File.expand_path(File.join(File.dirname(__FILE__), '../../lib'))
|
2
|
+
|
3
|
+
if File.exists?(File.join(lib_dir, 'daemons.rb'))
|
4
|
+
$LOAD_PATH.unshift lib_dir
|
5
|
+
else
|
6
|
+
require 'rubygems' rescue nil
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'daemons'
|
10
|
+
|
11
|
+
|
12
|
+
Daemons.run_proc('ctrl_proc_simple.rb') do
|
13
|
+
loop do
|
14
|
+
puts 'ping from proc!'
|
15
|
+
sleep(3)
|
16
|
+
end
|
17
|
+
end
|
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.2"
|
69
69
|
|
70
70
|
require 'daemons/daemonize'
|
71
71
|
|
@@ -92,7 +92,7 @@ module Daemons
|
|
92
92
|
# <tt>:dir_mode</tt>:: Either <tt>:script</tt> (the directory for writing the pid files to
|
93
93
|
# given by <tt>:dir</tt> is interpreted relative
|
94
94
|
# to the script location given by +script+) or <tt>:normal</tt> (the directory given by
|
95
|
-
# <tt>:dir</tt> is interpreted
|
95
|
+
# <tt>:dir</tt> is interpreted as a (absolute or relative) path) or <tt>:system</tt>
|
96
96
|
# (<tt>/var/run</tt> is used as the pid file directory)
|
97
97
|
#
|
98
98
|
# <tt>:dir</tt>:: Used in combination with <tt>:dir_mode</tt> (description above)
|
@@ -120,7 +120,7 @@ module Daemons
|
|
120
120
|
# :script => "path/to/script.rb"
|
121
121
|
# }
|
122
122
|
#
|
123
|
-
# Daemons.run(File.join(File.
|
123
|
+
# Daemons.run(File.join(File.dirname(__FILE__), 'myscript.rb'), options)
|
124
124
|
#
|
125
125
|
def run(script, options = {})
|
126
126
|
options[:script] = script
|
@@ -167,9 +167,10 @@ module Daemons
|
|
167
167
|
options[:mode] = :proc
|
168
168
|
options[:proc] = block
|
169
169
|
|
170
|
+
# we do not have a script location so the the :script option cannot be used, change it to :normal
|
170
171
|
if [nil, :script].include? options[:dir_mode]
|
171
172
|
options[:dir_mode] = :normal
|
172
|
-
options[:dir] = File.
|
173
|
+
options[:dir] = File.expand_path('.')
|
173
174
|
end
|
174
175
|
|
175
176
|
@controller = Controller.new(options, ARGV)
|
@@ -260,7 +261,6 @@ module Daemons
|
|
260
261
|
@group ||= ApplicationGroup.new('self', options)
|
261
262
|
|
262
263
|
@group.new_application(:mode => :none).start
|
263
|
-
|
264
264
|
end
|
265
265
|
module_function :daemonize
|
266
266
|
|
data/lib/daemons/application.rb
CHANGED
@@ -26,7 +26,7 @@ module Daemons
|
|
26
26
|
|
27
27
|
unless @pid = pid
|
28
28
|
if dir = pidfile_dir
|
29
|
-
@pid = PidFile.new(
|
29
|
+
@pid = PidFile.new(dir, @group.app_name, @group.multiple)
|
30
30
|
else
|
31
31
|
@pid = PidMem.new
|
32
32
|
end
|
@@ -45,9 +45,11 @@ module Daemons
|
|
45
45
|
(options[:log_output] && pidfile_dir()) ? File.join(pidfile_dir(), @group.app_name + '.output') : nil
|
46
46
|
end
|
47
47
|
|
48
|
+
|
49
|
+
# this function is only used to daemonize the currently running process (Daemons.daemonize)
|
48
50
|
def start_none
|
49
51
|
unless options[:ontop]
|
50
|
-
Daemonize.daemonize #(logfile)
|
52
|
+
Daemonize.daemonize(nil, @group.app_name) #(logfile)
|
51
53
|
else
|
52
54
|
Daemonize.simulate
|
53
55
|
end
|
@@ -86,11 +88,12 @@ module Daemons
|
|
86
88
|
|
87
89
|
def start_exec
|
88
90
|
unless options[:ontop]
|
89
|
-
Daemonize.daemonize(logfile)
|
91
|
+
Daemonize.daemonize(logfile, @group.app_name)
|
90
92
|
else
|
91
93
|
Daemonize.simulate(logfile)
|
92
94
|
end
|
93
95
|
|
96
|
+
# note that we cannot remove the pid file if we run in :ontop mode (i.e. 'ruby ctrl_exec.rb run')
|
94
97
|
@pid.pid = Process.pid
|
95
98
|
|
96
99
|
ENV['DAEMONS_ARGV'] = @controller_argv.join(' ')
|
@@ -101,7 +104,7 @@ module Daemons
|
|
101
104
|
|
102
105
|
def start_load
|
103
106
|
unless options[:ontop]
|
104
|
-
Daemonize.daemonize(logfile)
|
107
|
+
Daemonize.daemonize(logfile, @group.app_name)
|
105
108
|
else
|
106
109
|
Daemonize.simulate(logfile)
|
107
110
|
end
|
@@ -137,7 +140,7 @@ module Daemons
|
|
137
140
|
exit
|
138
141
|
}
|
139
142
|
|
140
|
-
#
|
143
|
+
# Now we really start the script...
|
141
144
|
$DAEMONS_ARGV = @controller_argv
|
142
145
|
ENV['DAEMONS_ARGV'] = @controller_argv.join(' ')
|
143
146
|
|
@@ -149,32 +152,71 @@ module Daemons
|
|
149
152
|
end
|
150
153
|
|
151
154
|
def start_proc
|
152
|
-
return unless options[:proc]
|
155
|
+
return unless p = options[:proc]
|
156
|
+
|
157
|
+
myproc = proc do
|
158
|
+
# We need this to remove the pid-file if the applications exits by itself.
|
159
|
+
# Note that <tt>at_text</tt> will only be run if the applications exits by calling
|
160
|
+
# <tt>exit</tt>, and not if it calls <tt>exit!</tt> (so please don't call <tt>exit!</tt>
|
161
|
+
# in your application!
|
162
|
+
#
|
163
|
+
at_exit {
|
164
|
+
@pid.cleanup rescue nil
|
165
|
+
|
166
|
+
# If the option <tt>:backtrace</tt> is used and the application did exit by itself
|
167
|
+
# create a exception log.
|
168
|
+
if options[:backtrace] and not options[:ontop] and not $daemons_sigterm
|
169
|
+
exception_log() rescue nil
|
170
|
+
end
|
171
|
+
|
172
|
+
}
|
173
|
+
|
174
|
+
# This part is needed to remove the pid-file if the application is killed by
|
175
|
+
# daemons or manually by the user.
|
176
|
+
# Note that the applications is not supposed to overwrite the signal handler for
|
177
|
+
# 'TERM'.
|
178
|
+
#
|
179
|
+
trap('TERM') {
|
180
|
+
@pid.cleanup rescue nil
|
181
|
+
$daemons_sigterm = true
|
182
|
+
|
183
|
+
exit
|
184
|
+
}
|
185
|
+
|
186
|
+
p.call()
|
187
|
+
end
|
153
188
|
|
154
189
|
unless options[:ontop]
|
155
|
-
@pid.pid = Daemonize.call_as_daemon(
|
190
|
+
@pid.pid = Daemonize.call_as_daemon(myproc, logfile, @group.app_name)
|
156
191
|
else
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
192
|
+
Daemonize.simulate(logfile)
|
193
|
+
|
194
|
+
@pid.pid = Process.pid
|
195
|
+
|
196
|
+
myproc.call
|
197
|
+
|
198
|
+
# why did we use this??
|
161
199
|
# Thread.new(&options[:proc])
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
200
|
+
|
201
|
+
# why did we use the code below??
|
202
|
+
# unless pid = Process.fork
|
203
|
+
# @pid.pid = pid
|
204
|
+
# Daemonize.simulate(logfile)
|
205
|
+
# options[:proc].call
|
206
|
+
# exit
|
207
|
+
# else
|
208
|
+
# Process.detach(@pid.pid)
|
209
|
+
# end
|
169
210
|
end
|
170
211
|
end
|
171
212
|
|
172
213
|
|
173
214
|
def start
|
174
|
-
@group.create_monitor(@group.applications[0] || self)
|
215
|
+
@group.create_monitor(@group.applications[0] || self) unless options[:ontop] # we don't monitor applications in the foreground
|
175
216
|
|
176
217
|
case options[:mode]
|
177
218
|
when :none
|
219
|
+
# this is only used to daemonize the currently running process
|
178
220
|
start_none
|
179
221
|
when :exec
|
180
222
|
start_exec
|
data/lib/daemons/controller.rb
CHANGED
data/lib/daemons/daemonize.rb
CHANGED
@@ -113,7 +113,7 @@ module Daemonize
|
|
113
113
|
|
114
114
|
|
115
115
|
def simulate(logfile_name = nil)
|
116
|
-
# NOTE: STDOUT and STDERR will not be redirected to the logfile
|
116
|
+
# NOTE: STDOUT and STDERR will not be redirected to the logfile, because in :ontop mode, we normally want to see the output
|
117
117
|
|
118
118
|
Dir.chdir "/" # Release old working directory
|
119
119
|
File.umask 0000 # Insure sensible umask
|
@@ -139,7 +139,7 @@ module Daemonize
|
|
139
139
|
module_function :simulate
|
140
140
|
|
141
141
|
|
142
|
-
def call_as_daemon(block, logfile_name = nil,
|
142
|
+
def call_as_daemon(block, logfile_name = nil, app_name = nil)
|
143
143
|
rd, wr = IO.pipe
|
144
144
|
|
145
145
|
if tmppid = safefork
|
@@ -152,6 +152,8 @@ module Daemonize
|
|
152
152
|
|
153
153
|
return pid
|
154
154
|
else
|
155
|
+
# child
|
156
|
+
|
155
157
|
rd.close
|
156
158
|
|
157
159
|
# Detach from the controlling terminal
|
@@ -160,14 +162,16 @@ module Daemonize
|
|
160
162
|
end
|
161
163
|
|
162
164
|
# Prevent the possibility of acquiring a controlling terminal
|
163
|
-
if oldmode.zero?
|
165
|
+
#if oldmode.zero?
|
164
166
|
trap 'SIGHUP', 'IGNORE'
|
165
167
|
exit if pid = safefork
|
166
|
-
end
|
168
|
+
#end
|
167
169
|
|
168
170
|
wr.write Process.pid
|
169
171
|
wr.close
|
170
172
|
|
173
|
+
$0 = app_name if app_name
|
174
|
+
|
171
175
|
Dir.chdir "/" # Release old working directory
|
172
176
|
File.umask 0000 # Insure sensible umask
|
173
177
|
|
@@ -210,7 +214,7 @@ module Daemonize
|
|
210
214
|
|
211
215
|
|
212
216
|
# This method causes the current running process to become a daemon
|
213
|
-
def daemonize(logfile_name = nil,
|
217
|
+
def daemonize(logfile_name = nil, app_name = nil)
|
214
218
|
srand # Split rand streams between spawning and daemonized process
|
215
219
|
safefork and exit # Fork and exit from the parent
|
216
220
|
|
@@ -220,11 +224,13 @@ module Daemonize
|
|
220
224
|
end
|
221
225
|
|
222
226
|
# Prevent the possibility of acquiring a controlling terminal
|
223
|
-
if oldmode.zero?
|
227
|
+
#if oldmode.zero?
|
224
228
|
trap 'SIGHUP', 'IGNORE'
|
225
229
|
exit if pid = safefork
|
226
|
-
end
|
230
|
+
#end
|
227
231
|
|
232
|
+
$0 = app_name if app_name
|
233
|
+
|
228
234
|
Dir.chdir "/" # Release old working directory
|
229
235
|
File.umask 0000 # Insure sensible umask
|
230
236
|
|
@@ -258,7 +264,8 @@ module Daemonize
|
|
258
264
|
|
259
265
|
STDERR.reopen STDOUT rescue nil
|
260
266
|
|
261
|
-
return oldmode ? sess_id : 0 # Return value is mostly irrelevant
|
267
|
+
#return oldmode ? sess_id : 0 # Return value is mostly irrelevant
|
268
|
+
return sess_id
|
262
269
|
end
|
263
270
|
module_function :daemonize
|
264
271
|
|
data/lib/daemons/pid.rb
CHANGED
@@ -1,72 +1,75 @@
|
|
1
|
-
|
2
|
-
module Daemons
|
3
|
-
|
4
|
-
class Pid
|
5
|
-
|
6
|
-
def Pid.running?(pid, additional = nil)
|
7
|
-
match_pid = Regexp.new("^\\s*#{pid}\\s")
|
8
|
-
got_match = false
|
9
|
-
|
10
|
-
ps_all = IO.popen("ps
|
11
|
-
ps_all.each { |psline|
|
12
|
-
next unless psline =~ match_pid
|
13
|
-
got_match = true
|
14
|
-
got_match = false if additional and psline !~ /#{additional}/
|
15
|
-
break
|
16
|
-
}
|
17
|
-
ps_all.close
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
# the
|
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
|
-
|
1
|
+
|
2
|
+
module Daemons
|
3
|
+
|
4
|
+
class Pid
|
5
|
+
|
6
|
+
def Pid.running?(pid, additional = nil)
|
7
|
+
match_pid = Regexp.new("^\\s*#{pid}\\s")
|
8
|
+
got_match = false
|
9
|
+
|
10
|
+
ps_all = IO.popen("ps ax") # the correct syntax is without a dash (-) !
|
11
|
+
ps_all.each { |psline|
|
12
|
+
next unless psline =~ match_pid
|
13
|
+
got_match = true
|
14
|
+
got_match = false if additional and psline !~ /#{additional}/
|
15
|
+
break
|
16
|
+
}
|
17
|
+
ps_all.close
|
18
|
+
|
19
|
+
# an alternative would be to use the code below, but I don't know whether this is portable
|
20
|
+
# `ps axo pid=`.split.include? pid.to_s
|
21
|
+
|
22
|
+
return got_match
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
# Returns the directory that should be used to write the pid file to
|
27
|
+
# depending on the given mode.
|
28
|
+
#
|
29
|
+
# Some modes may require an additionaly hint, others may determine
|
30
|
+
# the directory automatically.
|
31
|
+
#
|
32
|
+
# If no valid directory is found, returns nil.
|
33
|
+
#
|
34
|
+
def Pid.dir(dir_mode, dir, script)
|
35
|
+
# nil script parameter is allowed as long as dir_mode is not :script
|
36
|
+
return nil if dir_mode == :script && script.nil?
|
37
|
+
|
38
|
+
case dir_mode
|
39
|
+
when :normal
|
40
|
+
return File.expand_path(dir)
|
41
|
+
when :script
|
42
|
+
return File.expand_path(File.join(File.dirname(script),dir))
|
43
|
+
when :system
|
44
|
+
return '/var/run'
|
45
|
+
else
|
46
|
+
raise Error.new("pid file mode '#{dir_mode}' not implemented")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Initialization method
|
51
|
+
def initialize
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# Get method
|
56
|
+
def pid
|
57
|
+
end
|
58
|
+
|
59
|
+
# Set method
|
60
|
+
def pid=(p)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Cleanup method
|
64
|
+
def cleanup
|
65
|
+
end
|
66
|
+
|
67
|
+
# Exists? method
|
68
|
+
def exists?
|
69
|
+
true
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
|
72
75
|
end
|
data/lib/daemons/pidfile.rb
CHANGED
@@ -25,9 +25,9 @@ module Daemons
|
|
25
25
|
#
|
26
26
|
# Daemons is configurable to store the Pid-Files relative to three different locations:
|
27
27
|
# 1. in a directory relative to the directory where the script (the one that is supposed to run
|
28
|
-
# as a daemon) resides
|
29
|
-
# 2. in a directory
|
30
|
-
# 3. in the preconfigured directory <tt>/var/run</tt>
|
28
|
+
# as a daemon) resides (<tt>:script</tt> option for <tt>:dir_mode</tt>)
|
29
|
+
# 2. in a directory given by <tt>:dir</tt> (<tt>:normal</tt> option for <tt>:dir_mode</tt>)
|
30
|
+
# 3. in the preconfigured directory <tt>/var/run</tt> (<tt>:system</tt> option for <tt>:dir_mode</tt>)
|
31
31
|
#
|
32
32
|
class PidFile < Pid
|
33
33
|
|
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: 2006-
|
6
|
+
version: 1.0.2
|
7
|
+
date: 2006-10-04 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
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- examples/run/ctrl_proc.output
|
67
67
|
- examples/run/ctrl_proc.rb
|
68
68
|
- examples/run/ctrl_proc.rb.output
|
69
|
+
- examples/run/ctrl_proc_simple.rb
|
69
70
|
- examples/run/myserver.rb
|
70
71
|
- examples/run/myserver_crashing.rb
|
71
72
|
- examples/run/myserver_crashing.rb.output
|