Class: SLDB::ProcessRefresher
- Inherits:
-
Object
- Object
- SLDB::ProcessRefresher
- Defined in:
- lib/sldb.rb,
lib/sldb-0.2.0.rb
Overview
class Logger
Constant Summary collapse
- SIGNALS =
–{{{
%w( SIGTERM SIGINT SIGKILL )
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#refresh_rate ⇒ Object
readonly
Returns the value of attribute refresh_rate.
Instance Method Summary collapse
-
#initialize(path, refresh_rate = 8) ⇒ ProcessRefresher
constructor
A new instance of ProcessRefresher.
-
#kill ⇒ Object
–}}}.
Constructor Details
#initialize(path, refresh_rate = 8) ⇒ ProcessRefresher
Returns a new instance of ProcessRefresher.
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/sldb.rb', line 310 def initialize path, refresh_rate = 8 #--{{{ @path = path File::stat path @refresh_rate = Float refresh_rate @pipe = IO::pipe if((@pid = Util::fork)) @pipe.last.close @pipe = @pipe.first @thread = Thread::new{loop{@pipe.gets}} Process::detach @pid else begin SIGNALS.each{|sig| trap(sig){ exit! }} pid = Process::pid ppid = Process::ppid $0 = "#{ path }.refresher.#{ pid }" @pipe.first.close @pipe = @pipe.last loop do FileUtils::touch @path sleep @refresh_rate Process::kill 0, ppid @pipe.puts pid end rescue Exception => e exit! end end #--}}} end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
307 308 309 |
# File 'lib/sldb.rb', line 307 def path @path end |
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
308 309 310 |
# File 'lib/sldb.rb', line 308 def pid @pid end |
#refresh_rate ⇒ Object (readonly)
Returns the value of attribute refresh_rate.
309 310 311 |
# File 'lib/sldb.rb', line 309 def refresh_rate @refresh_rate end |
Instance Method Details
#kill ⇒ Object
–}}}
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/sldb.rb', line 341 def kill #--{{{ #Thread::new(Thread::current, @thread, @pipe) do |c, t, p| dead = false begin t.kill rescue nil p.close rescue nil SIGNALS.each do |sig| begin Process::kill sig, @pid sleep 0.01 Process::kill sig, @pid rescue Errno::ESRCH => e dead = true break rescue => e break end end ensure unless dead n = 42 begin n.times do |i| sleep 0.2 Process::kill 0, @pid sleep 1 end rescue Errno::ESRCH dead = true end current.raise "runaway refresher <#{ @pid }> must be killed!" unless dead end end #end #--}}} end |