averell23-watchdogger 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -0,0 +1,4 @@
1
+ =0.2.1
2
+
3
+ * Fixed log watcher not resetting status after trigger
4
+ * The killer action will now avoid re-execution for a configurable amount of time.
@@ -42,6 +42,7 @@ module Watcher
42
42
  is_triggered = false
43
43
  if(triggered?)
44
44
  is_triggered = "Found #{@match_str} in #{@file_name}"
45
+ reset_trigger
45
46
  end
46
47
  is_triggered
47
48
  rescue Exception => e
@@ -12,15 +12,24 @@ module WatcherAction
12
12
  # signal, if the process didn't die.
13
13
  # Defaults to KILL
14
14
  # [*wait*] Time to wait between signals (Default: 5)
15
+ # [*restart_time*] Time allowed for the process to restart. The action
16
+ # will not do anything if called again during this
17
+ # interval. (Default: 120)
15
18
  class KillProcess
16
19
 
17
20
  def initialize(config)
18
21
  @pidfile = config.get_value(:pidfile, false)
19
22
  @signals = config.get_list(:signal, 'KILL')
20
23
  @wait = config.get_value(:wait, 5).to_i
24
+ @restart_time = config.get_value(:restart_time, 120).to_i
21
25
  end
22
26
 
23
27
  def execute(event)
28
+ if(@last_action && (Time.now - @last_action).floor < @restart_time)
29
+ dog_log.info("Ignoring restart request in restarting time.")
30
+ return false
31
+ end
32
+
24
33
  Thread.new(@signals, @wait, @pidfile) do |signals, wait, pidfile|
25
34
  pid = File.open(pidfile) { |io| io.read }.to_i
26
35
  signals.each_with_index do |signal, index|
@@ -33,6 +42,7 @@ module WatcherAction
33
42
  end
34
43
  end
35
44
  end
45
+ @last_action = Time.now
36
46
  rescue Exception => e
37
47
  dog_log.warn { "Unable to kill process: #{e}" }
38
48
  end
@@ -5,11 +5,9 @@ PIDFILE = 'test.pid'
5
5
  class KillProcessTest < Test::Unit::TestCase
6
6
 
7
7
  def setup
8
- @killer = WatcherAction::KillProcess.new(:pidfile => PIDFILE)
8
+ @killer = WatcherAction::KillProcess.new(:pidfile => PIDFILE, :restart_time => '3')
9
9
  # Fork a dummy process that we can kill
10
- @pid = Process.fork { loop { sleep 1 }}
11
- @proc = Process.detach(@pid)
12
- File.open(PIDFILE, 'w') { |io| io << @pid }
10
+ fork_process
13
11
  end
14
12
 
15
13
  def teardown
@@ -26,4 +24,30 @@ class KillProcessTest < Test::Unit::TestCase
26
24
  assert_equal(false, @proc.status)
27
25
  end
28
26
 
27
+ def test_restart_killer
28
+ assert_not_equal(false, @proc.status)
29
+ @killer.execute(WatcherEvent.new)
30
+ sleep 1 # Wait for the sleep - the ruby process will handle the kill only then
31
+ assert_equal(false, @proc.status)
32
+ fork_process
33
+ # Within the restart time, this should be ignored
34
+ @killer.execute(WatcherEvent.new)
35
+ sleep 1
36
+ assert_not_equal(false, @proc.status)
37
+ sleep 2
38
+ # Now it should work again
39
+ @killer.execute(WatcherEvent.new)
40
+ sleep 1
41
+ assert_equal(false, @proc.status)
42
+ end
43
+
44
+ private
45
+
46
+ def fork_process
47
+ assert(!@proc || @proc.status == false, "Cannot refork with old proc running")
48
+ @pid = Process.fork { loop { sleep 1 }}
49
+ @proc = Process.detach(@pid)
50
+ File.open(PIDFILE, 'w') { |io| io << @pid }
51
+ end
52
+
29
53
  end
@@ -29,10 +29,11 @@ class LogWatcherTest < Test::Unit::TestCase
29
29
  def test_watcher_trigger
30
30
  File.open(logfile, 'a') do |io|
31
31
  20.times { io << 'nothing special' }
32
- io << 'da_test'
32
+ 10.times { io << 'da_test' }
33
33
  end
34
34
  sleep 2
35
35
  assert_kind_of(String, @watcher.watch_it!)
36
+ assert_equal(false, @watcher.watch_it!)
36
37
  end
37
38
 
38
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: averell23-watchdogger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Hahn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-17 00:00:00 -07:00
12
+ date: 2009-07-21 00:00:00 -07:00
13
13
  default_executable: watchdogger
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency