DCache mover killer
From SysadminWiki
By using the DCache python interface, you can create some usefull script for the day to day exploitation.
One example is the mover cleaner which will send a kill message to movers which have no gridftp instance attached to.
#!/usr/bin/python
##############################################################
#
# Jonathan Schaeffer, CCIN2P3, 2007
#
# Whithout arguments, this script scans all pools and hunts
# down dead movers by finding their relative GFTP transfer.
# If the mover is dead, it will be killed without mercy.
# You can pass some pools as argument to specify in which pool
# the killer has to look.
#
#
import adminDoor
import dCacheObjs
import sys
from time import sleep
from optparse import OptionParser
parser = OptionParser(version="CVS $Id: killDeadMovers.py,v 1.4 2007/02/28 09:31:54 jschaeff Exp $")
parser.add_option('-p','--pools', dest="pools", help="Comma separated list of pools", action="store", default=[])
parser.add_option('-v','--verify', dest="verif", help="Verify file existence in pnfs", action="store_true", default=False)
parser.add_option('-a','--all', dest="all", help="Run on each pools", action="store_true", default=False)
parser.add_option('-g','--pool-group', dest="pgroups", help="Coma separated list of pool groups", action="store", default=[])
(opt, args) = parser.parse_args()
adD=adminDoor.adminDoor()
cmd=[]
pnfsid_list=[]
moverCount=0
moverKilled=0
pools=[]
# get the list of pools
if opt.all :
pools=adD.exec_cmd(['cd PoolManager','psu ls pool'])[2:-4]
print '\033[1;33m* Warning\033[0;37m : You are executing this script on each pool'
print '\033[1;33m* Warning\033[0;37m : The script may hang on adminDoor connection'
print '\033[1;33m* Warning\033[0;37m : If this happens, try to pass one or several pool names as argument'
elif opt.pools :
pools=opt.pools.split(',')
elif opt.pgroups :
for name in opt.pgroups.split(',') :
pgroup = dCacheObjs.PoolGroup(name)
pgroup.populate(adD.exec_cmd(['cd PoolManager','psu ls pgroup -l '+name])[2:-4])
for p in pgroup.getPools() :
pools.append(p.getName())
print '\033[1;32m* \033[0;37mComposing the housecleaning commands :'
print pools
for pool in pools:
# get the dead transfers :
movers = adD.exec_cmd(['cd '+pool, 'mover ls'])[2:-4]
sleep(1)
# list gridftp transfers
cmd.append('cd '+pool)
print (cmd[-1])
for mov in movers:
if mov[:2].isdigit():
moverCount = moverCount+1
mover=dCacheObjs.Mover(pool)
mover.populate(mov)
cell = mover.longid.split('@')[1].split(':')[0]
test = adD.exec_cmd(['cd '+cell, 'info'])[2]
if test.find('No Route',0,14)>=0 and mover.longid.find('GFTP')>=0 and mover.lm > 300 :
cmd.append("mover kill %i"%(mover.id))
print (cmd[-1])
pnfsid_list.append(mover.pnfsid)
moverKilled=moverKilled+1
cmd.append('..')
print (cmd[-1])
if len(cmd) >0:
print '* Executing the commands'
adD.exec_cmd(cmd)
print ("* Killed %i movers out of %i")%(moverKilled,moverCount)
if opt.verif :
print ("\033[1;32m* \033[0;37mMovers were hanged on file :")
for m in pnfsid_list:
print ' - ' + m
print ' ' + adD.exec_cmd(['cd PnfsManager','pathfinder '+m])[2]
print ' cacheinfo : ' + adD.exec_cmd(['cd PnfsManager','cacheinfoof '+m])[2]
