]> git.notmuchmail.org Git - sup/blob - lib/sup/suicide.rb
die gracefully upon SIGKILL
[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   def please_die!; @die = true end
18
19   def start
20     @thread = Redwood::reporting_thread("suicide watch") do
21       while true
22         sleep DELAY
23         if File.exists? @fn
24           FileUtils.rm_f @fn
25           @die = true
26         end
27       end
28     end
29   end
30
31   def stop
32     @thread.kill if @thread
33     @thread = nil
34   end
35 end
36
37 end