Module: EtcdTools::Watchdog::Threads

Included in:
Init
Defined in:
lib/etcd-tools/watchdog/threads/etcd.rb,
lib/etcd-tools/watchdog/threads/icmp.rb

Instance Method Summary collapse

Instance Method Details

#thread_etcdObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/etcd-tools/watchdog/threads/etcd.rb', line 4

def thread_etcd
  Thread.new do
    debug '<etcd> starting thread...'
    etcd = etcd_connect!
    while !@exit do
      debug '<etcd> checking etcd state'
      status = leader? etcd
      @semaphore[:etcd].synchronize { @status_etcd = status }
      debug "<etcd> i am #{status ? 'the leader' : 'not a leader' }"
      sleep @config[:parameters][:etcd_interval]
    end
    info '<etcd> ending thread...'
  end
end

#thread_icmpObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/etcd-tools/watchdog/threads/icmp.rb', line 6

def thread_icmp
  Thread.new do
    debug '<icmp> starting thread...'
    icmp = Net::Ping::ICMP.new(@config[:parameters][:vip])
    while !@exit do
      debug '<icmp> checking state by ping'
      status = vip_alive? icmp
      @semaphore[:icmp].synchronize { @status_icmp = status }
      debug "<icmp> VIP is #{status ? 'alive' : 'down' }"
      sleep @config[:parameters][:icmp_interval]
    end
    info '<icmp> ending thread...'
  end
end