0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 01:21:03 +01:00
mongodb/buildscripts/cleanbb.py

69 lines
1.5 KiB
Python
Raw Normal View History

2010-02-04 16:21:36 +01:00
import sys
import os
import utils
import time
2010-06-02 19:21:29 +02:00
cwd = os.getcwd();
if cwd.find("buildscripts" ) > 0 :
cwd = cwd.partition( "buildscripts" )[0]
print( "cwd [" + cwd + "]" )
def shouldKill( c ):
if c.find( cwd ) >= 0:
return True
2010-06-03 18:54:38 +02:00
if ( c.find( "buildbot" ) >= 0 or c.find( "slave" ) ) and c.find( "/mongo/" ) >= 0:
2010-06-02 19:21:29 +02:00
return True
return False
2010-02-04 16:21:36 +01:00
def killprocs( signal="" ):
killed = 0
2010-06-02 21:03:03 +02:00
l = utils.getprocesslist()
print( "num procs:" + str( len( l ) ) )
if len(l) == 0:
print( "no procs" )
try:
print( execsys( "/sbin/ifconfig -a" ) )
except Exception,e:
print( "can't get interfaces" + str( e ) )
for x in l:
2010-02-04 16:21:36 +01:00
x = x.lstrip()
2010-06-02 19:21:29 +02:00
if not shouldKill( x ):
2010-02-04 16:21:36 +01:00
continue
pid = x.partition( " " )[0]
print( "killing: " + x )
utils.execsys( "/bin/kill " + signal + " " + pid )
killed = killed + 1
return killed
def cleanup( root ):
2010-06-02 19:39:01 +02:00
if killprocs() > 0:
time.sleep(3)
killprocs("-9")
2010-02-04 16:21:36 +01:00
# delete all regular files, directories can stay
# NOTE: if we delete directories later, we can't delete diskfulltest
for ( dirpath , dirnames , filenames ) in os.walk( root , topdown=False ):
for x in filenames:
2010-06-02 21:14:51 +02:00
foo = dirpath + "/" + x
print( "removing: " + foo )
os.remove( foo )
2010-02-04 16:21:36 +01:00
if __name__ == "__main__":
root = "/data/db/"
if len( sys.argv ) > 1:
root = sys.argv[1]
cleanup( root )