Kill hung frame listeners on each verify networks event

Network checker relies on interrupt signal for its own
internal logic, so after interrupt is received - it will
do some parsing work and wont finish immediatly.

But before starting frame listeners in a new run - old frame
listeners may be not interrupted because mcollective failed
due timeout or any other not predicted problem.
So, we need to completely shutdown frame listeners with kill -9

Tested:
  Spawned bunch of - /usr/bin/python /usr/bin/net_probe.py -c listen.conf
  Executed network verification from UI - all old listeners were killed,
  verification succeeded.
  Also, executed same test with removed pid files in /var/run/net_probe folder

Change-Id: I7aa48d00b3f86827ba9860a3e3797ed5bd0eb713
Closes-Bug: 1466020
This commit is contained in:
Dmitry Shulyak 2015-06-18 11:57:50 +03:00
parent 776157f722
commit 7fff2f88a6
1 changed files with 19 additions and 12 deletions

View File

@ -22,6 +22,7 @@ module MCollective
class Net_probe<RPC::Agent
def startup_hook
@pattern = "/var/tmp/net-probe-dump*"
@piddir = '/var/run/net_probe'
end
action "multicast_listen" do
@ -42,7 +43,7 @@ module MCollective
end
action "start_frame_listeners" do
cleanup_netprobe
kill_frame_listeners
start_frame_listeners
end
@ -99,11 +100,6 @@ module MCollective
end
end
def cleanup_netprobe
status = run("pkill net_probe.py && sleep 2 && pgrep net_probe.py")
reply.fail! "Cant stop net_probe.py execution." unless status == 1
end
def start_frame_listeners
validate :interfaces, String
config = {
@ -118,9 +114,6 @@ module MCollective
config.merge!(JSON.parse(request[:config]))
end
# we want to be sure that there is no frame listeners running
stop_frame_listeners
# wipe out old stuff before start
Dir.glob(@pattern).each do |file|
File.delete file
@ -202,9 +195,23 @@ module MCollective
f
end
def kill_frame_listeners
net_probe_pattern = 'net_probe.py'
Dir.glob('/proc/[0-9]*/cmdline').each do |proc|
if File.read(proc).include? net_probe_pattern
Process.kill('KILL', proc.split('/')[2].to_i)
end
end
# and wipe out all old pidfiles
Dir.glob(File.join(@piddir, '*')).each do |pidfile|
File.unlink(pidfile)
end
end
def stop_frame_listeners
piddir = "/var/run/net_probe"
pidfiles = Dir.glob(File.join(piddir, '*'))
pidfiles = Dir.glob(File.join(@piddir, '*'))
# Send SIGINT to all PIDs in piddir.
pidfiles.each do |f|
begin
@ -226,7 +233,7 @@ module MCollective
end
end
end
pidfiles = Dir.glob(File.join(piddir, '*'))
pidfiles = Dir.glob(File.join(@piddir, '*'))
end
end
end