def main(work_dir, force=False):
    retries_count = 100
    sleep_in_retries = 0.2
    # get the pids
    try:
        frontend_pid = glideinFrontendPidLib.get_frontend_pid(work_dir)
    except RuntimeError, e:
        print e
        return 1
Exemple #2
0
def main(work_dir, force=False):
    retries_count = 50
    sleep_in_retries = 0.6
    # get the pids
    try:
        frontend_pid = glideinFrontendPidLib.get_frontend_pid(work_dir)
    except RuntimeError, e:
        print e
        if str(e) == "Frontend not running":
            # Workaround to distinguish when the frontend is not running
            # string must be the same as in glideinFrontendPidLib
            return 2
        return 1
def main(work_dir, force=False):
    retries_count = 50
    sleep_in_retries = 0.6
    # get the pids
    try:
        frontend_pid = glideinFrontendPidLib.get_frontend_pid(work_dir)
    except RuntimeError as e:
        print(e)
        if str(e) == "Frontend not running":
            # Workaround to distinguish when the frontend is not running
            # string must be the same as in glideinFrontendPidLib
            return 2
        return 1
    #print frontend_pid

    if not glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
        # Frontend already dead
        return 0

    # kill processes
    # first soft kill the frontend (30s timeout, retries_count*sleep_in_retries )
    try:
        os.kill(frontend_pid, signal.SIGTERM)
    except OSError:
        pass # frontend likely already dead

    for retries in range(retries_count):
        if glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
            time.sleep(sleep_in_retries)
        else:
            return 0 # frontend dead

    if not force:
        print("Frontend did not die after the timeout of %s sec" % (retries_count * sleep_in_retries))
        return 1

    # Retry soft kill the frontend ... should exit now
    print("Frontend still alive ... retrying soft kill")
    try:
        os.kill(frontend_pid, signal.SIGTERM)
    except OSError:
        pass # frontend likely already dead

    for retries in range(retries_count):
        if glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
            time.sleep(sleep_in_retries)
        else:
            return 0 # frontend dead

    print("Frontend still alive ... sending hard kill")

    element_pids = get_element_pids(work_dir, frontend_pid)
    #print element_pids

    element_keys = sorted(element_pids.keys())

    for element in element_keys:
        if glideinFrontendPidLib.pidSupport.check_pid(element_pids[element]):
            print("Hard killing element %s" % element)
            try:
                os.kill(element_pids[element], signal.SIGKILL)
            except OSError:
                pass # ignore already dead processes

    if not glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
        return 0 # Frontend died

    try:
        os.kill(frontend_pid, signal.SIGKILL)
    except OSError:
        pass # ignore problems
    return 0
#
# Project:
#   glideinWMS
#
# File Version: 
#
# Description:
#   Check if a glideinFrontend is running
# 
# Arguments:
#   $1 = work_dir
#
# Author:
#   Igor Sfiligoi
#

import sys,os.path
sys.path.append(os.path.join(sys.path[0],"../.."))
from glideinwms.frontend import glideinFrontendPidLib

try:
    work_dir=sys.argv[1]
    frontend_pid=glideinFrontendPidLib.get_frontend_pid(work_dir)
except:
    print "Not running"
    sys.exit(1)

print "Running"
sys.exit(0)

Exemple #5
0
def main(work_dir, force=False):
    retries_count = 50
    sleep_in_retries = 0.6
    # get the pids
    try:
        frontend_pid = glideinFrontendPidLib.get_frontend_pid(work_dir)
    except RuntimeError as e:
        print(e)
        if str(e) == "Frontend not running":
            # Workaround to distinguish when the frontend is not running
            # string must be the same as in glideinFrontendPidLib
            return 2
        return 1
    #print frontend_pid

    if not glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
        # Frontend already dead
        return 0

    # kill processes
    # first soft kill the frontend (30s timeout, retries_count*sleep_in_retries )
    try:
        os.kill(frontend_pid, signal.SIGTERM)
    except OSError:
        pass  # frontend likely already dead

    for retries in range(retries_count):
        if glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
            time.sleep(sleep_in_retries)
        else:
            return 0  # frontend dead

    if not force:
        print("Frontend did not die after the timeout of %s sec" %
              (retries_count * sleep_in_retries))
        return 1

    # Retry soft kill the frontend ... should exit now
    print("Frontend still alive ... retrying soft kill")
    try:
        os.kill(frontend_pid, signal.SIGTERM)
    except OSError:
        pass  # frontend likely already dead

    for retries in range(retries_count):
        if glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
            time.sleep(sleep_in_retries)
        else:
            return 0  # frontend dead

    print("Frontend still alive ... sending hard kill")

    element_pids = get_element_pids(work_dir, frontend_pid)
    #print element_pids

    element_keys = sorted(element_pids.keys())

    for element in element_keys:
        if glideinFrontendPidLib.pidSupport.check_pid(element_pids[element]):
            print("Hard killing element %s" % element)
            try:
                os.kill(element_pids[element], signal.SIGKILL)
            except OSError:
                pass  # ignore already dead processes

    if not glideinFrontendPidLib.pidSupport.check_pid(frontend_pid):
        return 0  # Frontend died

    try:
        os.kill(frontend_pid, signal.SIGKILL)
    except OSError:
        pass  # ignore problems
    return 0