2008-04-11
mongrel进程自动监控脚本
windows下跑mongrel服务经常会出死连接问题:
the proxy received an invalid response from server
原因是mongrel进程堵塞掉了
一开始我认为只是写个脚本监听http端口,如果堵塞就自动关闭并启动对应系统服务
今天仔细研究了一下发现不能这么处理
系统服务堵塞时候,对应的ruby进程有可能有tcp连接处于close_waite状态
这个时候,系统服务是启动不了的
必须找到对应的进程kill掉才能重启mongrel进程
查找某端口绑定的进程是这个命令:
netstat -ao | find "3000"
这个命令是结束一个windows进程:
ntsd -c q -p 4004
记录一下这个处理脚本:
require 'open-uri'
balance = [3001,3002,3003,3004,3005,3006,3007,3008,3009]
def restart port
file = rand.to_s+'.txt'
puts file
begin
Timeout.timeout(1){system 'netstat -ao | find "'+port+'" > '+file}
rescue Exception
end
k=open(file)
c = k.read
puts c
c=~/CLOSE_WAIT\s+(\w+)/
puts $1
if $1
system 'ntsd -c q -p '+$1.to_s
system 'net stop blogblo'+(port.to_i-3000).to_s
system 'net start blogblo'+(port.to_i-3000).to_s
end
system 'ntsd -c q -pn netstat.exe'
sleep 2
k.close
File.delete file
end
c = 'kk'
for b in balance
puts 'open http://localhost:'+b.to_s+'/index/void'
begin
c = open('http://localhost:'+b.to_s+'/index/void').read
puts c
if c != 'haha'
puts 'reartart'
restart b.to_s
end
rescue Exception
puts 'fail'
restart b.to_s
end
end
--------------
chenjinlai
2008-04-11
the proxy received an invalid response from server
原因是mongrel进程堵塞掉了
一开始我认为只是写个脚本监听http端口,如果堵塞就自动关闭并启动对应系统服务
今天仔细研究了一下发现不能这么处理
系统服务堵塞时候,对应的ruby进程有可能有tcp连接处于close_waite状态
这个时候,系统服务是启动不了的
必须找到对应的进程kill掉才能重启mongrel进程
查找某端口绑定的进程是这个命令:
netstat -ao | find "3000"
这个命令是结束一个windows进程:
ntsd -c q -p 4004
记录一下这个处理脚本:
require 'open-uri'
balance = [3001,3002,3003,3004,3005,3006,3007,3008,3009]
def restart port
file = rand.to_s+'.txt'
puts file
begin
Timeout.timeout(1){system 'netstat -ao | find "'+port+'" > '+file}
rescue Exception
end
k=open(file)
c = k.read
puts c
c=~/CLOSE_WAIT\s+(\w+)/
puts $1
if $1
system 'ntsd -c q -p '+$1.to_s
system 'net stop blogblo'+(port.to_i-3000).to_s
system 'net start blogblo'+(port.to_i-3000).to_s
end
system 'ntsd -c q -pn netstat.exe'
sleep 2
k.close
File.delete file
end
c = 'kk'
for b in balance
puts 'open http://localhost:'+b.to_s+'/index/void'
begin
c = open('http://localhost:'+b.to_s+'/index/void').read
puts c
if c != 'haha'
puts 'reartart'
restart b.to_s
end
rescue Exception
puts 'fail'
restart b.to_s
end
end
--------------
chenjinlai
2008-04-11







评论排行榜