]> git.cworth.org Git - sup/blob - lib/sup/suicide.rb
98b43462eea250aa6969221d0a8456b9697bd54a
[sup] / lib / sup / suicide.rb
1 module Redwood
2
3 class SuicideManager
4   include Singleton
5
6   DELAY = 5
7
8   def initialize fn
9     @fn = fn
10     @die = false
11     @thread = nil
12     self.class.i_am_the_instance self
13     FileUtils.rm_f @fn
14   end
15
16   bool_reader :die
17
18   def start
19     @thread = Redwood::reporting_thread("suicide watch") do
20       while true
21         sleep DELAY
22         if File.exists? @fn
23           FileUtils.rm_f @fn
24           @die = true
25         end
26       end
27     end
28   end
29
30   def stop
31     @thread.kill if @thread
32     @thread = nil
33   end
34 end
35
36 end