예제 #1
0
def getPortsFile(baseport):
    '''
    Returns the file containing a list of containers and used ports
    '''
    
    #initialize the return value
    ret_val = None
    
    #directory where all the process IDs of this particular instance of 
    #ACS are stored
    ACS_TMP_DIR = getAcsTmpDirectoryPath()
    ACS_INSTANCE_DIR = ACS_TMP_DIR + '/ACS_INSTANCE.' + str(baseport)

    #make sure the acs instance directory exists
    if not exists(ACS_INSTANCE_DIR):
        #assume everything is running remotely
        ACS_INSTANCE_DIR = ACS_TMP_DIR
        if not exists(ACS_INSTANCE_DIR):
            stderr.write("$ACS_TMP_DIR does not exist!\n")
            exit(1)
            
    #make sure the user actually has write access to this ACS instance
    elif not access(ACS_INSTANCE_DIR, R_OK & W_OK & X_OK & F_OK):
        stderr.write("The ACS instance in '" +
                     str(ACS_INSTANCE_DIR) +
                     "' is not accessible by this user!\n")
        exit(1)
    
    #make sure the file full of port numbers exists. if it does not, create it
    if not exists(ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS'):
        system('touch ' + ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS')
        system ('chmod 774 ' + ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS')
        if __DEBUG__:
            stderr.write("USED_CONTAINER_PORTS did not exist\n")

    #go to it
    chdir(ACS_INSTANCE_DIR)

    #lock it
    gotlock = False
    while not gotlock:
        try:
            if os.name != 'nt':
                link('USED_CONTAINER_PORTS', 'USED_CONTAINER_PORTS.lock')
            else:
                if exists('USED_CONTAINER_PORTS.lock'):
                    raise OSError;
                system('touch USED_CONTAINER_PORTS.lock')
            gotlock = True
        except OSError:
            continue
    
    #open the file
    ret_val = open('USED_CONTAINER_PORTS', 'r+')
    
    return ret_val
예제 #2
0
def getPortsFile(baseport):
    '''
    Returns the file containing a list of containers and used ports
    '''

    #initialize the return value
    ret_val = None

    #directory where all the process IDs of this particular instance of
    #ACS are stored
    ACS_TMP_DIR = getAcsTmpDirectoryPath()
    ACS_INSTANCE_DIR = ACS_TMP_DIR + '/ACS_INSTANCE.' + str(baseport)

    #make sure the acs instance directory exists
    if not exists(ACS_INSTANCE_DIR):
        #assume everything is running remotely
        ACS_INSTANCE_DIR = ACS_TMP_DIR
        if not exists(ACS_INSTANCE_DIR):
            stderr.write("$ACS_TMP_DIR does not exist!\n")
            exit(1)

    #make sure the user actually has write access to this ACS instance
    elif not access(ACS_INSTANCE_DIR, R_OK & W_OK & X_OK & F_OK):
        stderr.write("The ACS instance in '" + str(ACS_INSTANCE_DIR) +
                     "' is not accessible by this user!\n")
        exit(1)

    #make sure the file full of port numbers exists. if it does not, create it
    if not exists(ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS'):
        system('touch ' + ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS')
        system('chmod 774 ' + ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS')
        if __DEBUG__:
            stderr.write("USED_CONTAINER_PORTS did not exist\n")

    #go to it
    chdir(ACS_INSTANCE_DIR)

    #lock it
    gotlock = False
    while not gotlock:
        try:
            if os.name != 'nt':
                link('USED_CONTAINER_PORTS', 'USED_CONTAINER_PORTS.lock')
            else:
                if exists('USED_CONTAINER_PORTS.lock'):
                    raise OSError
                system('touch USED_CONTAINER_PORTS.lock')
            gotlock = True
        except OSError:
            continue

    #open the file
    ret_val = open('USED_CONTAINER_PORTS', 'r+')

    return ret_val
예제 #3
0
def getPortsFile(baseport):
    '''
    Returns the file containing a list of notify services and used ports
    '''
    
    #initialize the return value
    ret_val = None
    
    #directory where all the process IDs of this particular instance of 
    #ACS are stored
    ACS_TMP_DIR = getAcsTmpDirectoryPath()
    ACS_INSTANCE_DIR = ACS_TMP_DIR + '/ACS_INSTANCE.' + str(baseport)

    #make sure the acs instance directory exists
    if not exists(ACS_INSTANCE_DIR):
        #assume everything is running remotely
        ACS_INSTANCE_DIR = ACS_TMP_DIR
        if not exists(ACS_INSTANCE_DIR):
            stderr.write("$ACS_TMP_DIR does not exist!\n")
            exit(1)
            
    #make sure the user actually has write access to this ACS instance
    elif not access(ACS_INSTANCE_DIR, R_OK & W_OK & X_OK & F_OK):
        stderr.write("The ACS instance in '" +
                     str(ACS_INSTANCE_DIR) +
                     "' is not accessible by this user!\n")
        exit(1)
    
    #make sure the file full of port numbers exists. if it does not, create it
    if not exists(ACS_INSTANCE_DIR + '/USED_NOTIFY_PORTS'):
        system('touch ' + ACS_INSTANCE_DIR + '/USED_NOTIFY_PORTS')
        system ('chmod 774 ' + ACS_INSTANCE_DIR + '/USED_NOTIFY_PORTS')
        if __DEBUG__:
            stderr.write("USED_NOTIFY_PORTS did not exist\n")

    #go to it
    chdir(ACS_INSTANCE_DIR)
    
    #open the file
    ret_val = open('USED_NOTIFY_PORTS', 'r+')
    
    #lock it
    lockf(ret_val.fileno(), LOCK_EX)
    
    return ret_val
예제 #4
0
def getPortsFile(baseport):
    '''
    Returns the file containing a list of notify services and used ports
    '''

    #initialize the return value
    ret_val = None

    #directory where all the process IDs of this particular instance of
    #ACS are stored
    ACS_TMP_DIR = getAcsTmpDirectoryPath()
    ACS_INSTANCE_DIR = ACS_TMP_DIR + '/ACS_INSTANCE.' + str(baseport)

    #make sure the acs instance directory exists
    if not exists(ACS_INSTANCE_DIR):
        #assume everything is running remotely
        ACS_INSTANCE_DIR = ACS_TMP_DIR
        if not exists(ACS_INSTANCE_DIR):
            stderr.write("$ACS_TMP_DIR does not exist!\n")
            exit(1)

    #make sure the user actually has write access to this ACS instance
    elif not access(ACS_INSTANCE_DIR, R_OK & W_OK & X_OK & F_OK):
        stderr.write("The ACS instance in '" + str(ACS_INSTANCE_DIR) +
                     "' is not accessible by this user!\n")
        exit(1)

    #make sure the file full of port numbers exists. if it does not, create it
    if not exists(ACS_INSTANCE_DIR + '/USED_NOTIFY_PORTS'):
        system('touch ' + ACS_INSTANCE_DIR + '/USED_NOTIFY_PORTS')
        system('chmod 774 ' + ACS_INSTANCE_DIR + '/USED_NOTIFY_PORTS')
        if __DEBUG__:
            stderr.write("USED_NOTIFY_PORTS did not exist\n")

    #go to it
    chdir(ACS_INSTANCE_DIR)

    #open the file
    ret_val = open('USED_NOTIFY_PORTS', 'r+')

    #lock it
    lockf(ret_val.fileno(), LOCK_EX)

    return ret_val
예제 #5
0
def getPortsFile():
    '''
    Returns the file containing a list of containers and used ports.
    In the event of error, bails out of Python.
    '''
    
    #initialize the return value
    ret_val = None
    
    #directory where all the process IDs of this particular instance of 
    #ACS are stored
    ACS_TMP_DIR = getAcsTmpDirectoryPath()

    ACS_INSTANCE_DIR = ACS_TMP_DIR + '/ACS_INSTANCE.' + str(cl_baseport)

    #make sure the acs instance directory exists
    if not exists(ACS_INSTANCE_DIR):
        stderr.write("$ACS_TMP_DIR/ACS_INSTANCE.$ACS_INSTANCE does not exist!\n")
        exit(1)
            
    #make sure the user actually has write access to this ACS instance
    elif not access(ACS_INSTANCE_DIR, R_OK & W_OK & X_OK & F_OK):
        stderr.write("The ACS instance in '" +
                     str(ACS_INSTANCE_DIR) +
                     "' is not accessible by this user!\n")
        exit(1)
    
    #make sure the file full of port numbers exists. if it does not, create it
    if not exists(ACS_INSTANCE_DIR + '/USED_CONTAINER_PORTS'):
        stderr.write("The USED_CONTAINER_PORTS file for the ACS instance in '" +
                     str(ACS_INSTANCE_DIR) +
                     "' does not exist!\n")
        exit(1)

    #go to it
    chdir(ACS_INSTANCE_DIR)
    
    #open the file
    ret_val = open('USED_CONTAINER_PORTS', 'r')
    
    #lock it
    lockf(ret_val.fileno(), LOCK_SH)
    
    return ret_val
예제 #6
0
from sys import argv
from sys import exit

from fcntl   import lockf 
from fcntl   import LOCK_EX
from os.path import exists

from optparse import OptionParser
import socket
from AcsutilPy.ACSDirectory import getAcsTmpDirectoryPath
from AcsutilPy.AcsInstanceLockHelper import AcsInstanceLockHelper
################################################################################################

#first thing we do is create a lock so this command cannot be run again until it
#finishes
ACS_INSTANCE_DIR = getAcsTmpDirectoryPath()
lock_file_name=ACS_INSTANCE_DIR + '.killACS.lock'
#sanity check to ensure the temp directory exists
if exists(ACS_INSTANCE_DIR):
    #sanity check to ensure the file exists
    if not exists(lock_file_name):
        lock_file = open(lock_file_name, 'w')
    else:
        print "\nAborted: lock file already exists:",lock_file_name,'\n'
        exit(-1)
else:
    # Temporary folder does not exists: run with no lock_file
    lock_file = None
    lock_file_name = None

parser = OptionParser(usage="This script is used as an alternative to rebooting your machine to regain TCP ports and you should report the exact circumstances that caused you to use it to the [email protected] mailing list! Also, this will 'decapitate' other instances of ACS run by other users of this system!\n\nFor quick performance that kills all Java clients (similar behavior killACS had with older versions of ACS)\nRun:\n     killACS -q -a\nBe forewarned this kills all Java virtual machines though.")
예제 #7
0
               except:
                   print "Unable to remove this file:", entry  
   
   except Exception, e:
       print "An exception occurred in acsdataClean.py's main:", e


if argv.count("-h")!=0 or argv.count("--help")!=0:
   print "Clean the temporal directories of ACS, as given by $ACS_TMP, or otherwise $ACSDATA/tmp"
   print "Options:"
   print "-h or --help : Show this message and then exit.\n"
   print "-all : acsdataClean will remove all the directory entries under the tmp directory. Without this option, the ACS_INSTANCE.* subdirectories are preserved.\n"
   print "-other_hosts : acsdataClean will clean all directories located under $ACSDATA/tmp/, thus cleaning also the tmp directories of other hosts sharing the $ACSDATA in the same machine.\n"
   exit(0)

print "Cleaning up ACS temporary directories"
myDir = getAcsTmpDirectoryPath()
cleanDirectory(myDir)
if argv.count("-other_hosts")!=0:
   print "Cleaning all the possible hosts' temporary directories"
   myDir = str(environ['ACSDATA']) + '/tmp/'
   if not exists(myDir):
      print "'", myDir, "' does not exist!"
      exit(1)
   fileList = listdir(myDir)
   for file in fileList:
      if isdir(myDir + file):
         print "Cleaning " + file
         cleanDirectory(myDir + file)