def watchdog_loop():
    run_dir = safplus.SAFPLUS_RUN_DIR
    reboot_file  = run_dir + '/' + safplus.SAFPLUS_REBOOT_FILE
    stop_file    = run_dir + '/' + safplus.SAFPLUS_STOP_FILE
    safplus.safe_remove(reboot_file)
    safplus.remove_stop_file()
    amfproc = None
    global fileLogger

    while True:
        try:
            #pid = safplus.get_amf_pid()
            #if pid == 0:
            if not amfproc:
                if os.path.isfile(stop_file) and not os.path.isfile(reboot_file):
                    logging.info("Stop file exists: SAFplus is stopping")
                    return
                else:                           # Restart AMF if stop file not found
                    logging.info("Stop file not found: Starting AMF from watchdog")
                    safplus.kill_amf()  # when AMF dies, kill all its children to make sure there are no orphaned processes hanging around.  This only kills binaries in the bin directory, rather than all children...
                    #This fixes the rapid restart using kill -9 (amf) and UDP keepalives
                    #Restart delay in the watchdog to make sure we got the keepalive timeout.
                    wdSleep(SAFPLUS_POLL_INTERVAL/2)
                    amfproc = safplus.cleanup_and_start_ams()
                    if safplus.reconfigWdLog:
                        fileLogger.handlers = []
                        configWatchdogLog()
                        safplus.reconfigWdLog = False

            # Python 3:
#            try:
#              Python 3: amfproc.wait(SAFPLUS_POLL_INTERVAL)
#              del amfproc
#              amfproc = None
#            except subprocess.TimeoutExpired, e:
#              pass

#            if amfproc.poll():
#              del amfproc
#              amfproc = None
#            wdSleep(SAFPLUS_POLL_INTERVAL)
            amfproc.wait() 
            del amfproc
            amfproc = None

        except Exception, e:
            print "Exception: %s" % str(e)
            time.sleep(5)
Example #2
0
def watchdog_loop():
    run_dir = safplus.SAFPLUS_RUN_DIR
    reboot_file  = run_dir + '/' + safplus.SAFPLUS_REBOOT_FILE
    stop_file    = run_dir + '/' + safplus.SAFPLUS_STOP_FILE
    safplus.safe_remove(reboot_file)
    safplus.remove_stop_file()
    amfproc = None

    while True:
        try:
            #pid = safplus.get_amf_pid()
            #if pid == 0:
            if not amfproc:
                if os.path.isfile(stop_file):   # Kill watchdog if stop file exists        
                    logging.info("Stop file exists: SAFplus is stopping")
                    return
                else:                           # Restart AMF if stop file not found
                    logging.info("Stop file not found: Starting AMF from watchdog")
                    safplus.kill_amf()  # when AMF dies, kill all its children to make sure there are no orphaned processes hanging around.  This only kills binaries in the bin directory, rather than all children...
                    amfproc = safplus.cleanup_and_start_ams()
            # Python 3:
#            try:
#              Python 3: amfproc.wait(SAFPLUS_POLL_INTERVAL)
#              del amfproc
#              amfproc = None
#            except subprocess.TimeoutExpired, e:
#              pass

#            if amfproc.poll():
#              del amfproc
#              amfproc = None
#            wdSleep(SAFPLUS_POLL_INTERVAL)
            amfproc.wait() 
            del amfproc
            amfproc = None

        except Exception, e:
            print "Exception: %s" % str(e)
            time.sleep(5)
Example #3
0
def restart_safplus():
    # remove no restart file, to make sure a restart occurs
    safplus.remove_stop_file()
    safplus.create_reboot_file()
    safplus.stop_amf()
def restart_safplus():
    # remove no restart file, to make sure a restart occurs
    safplus.remove_stop_file()
    safplus.stop_amf()