def watchdog_loop():
    run_dir = asp.get_asp_run_dir()
#    no_restart_file = run_dir + '/' + ASP_NO_RESTART_FILE
#    watchdog_restart_file = run_dir + '/' + ASP_WATCHDOG_RESTART_FILE
#    restart_disable_file = run_dir + '/' + ASP_RESTART_DISABLE_FILE
    reboot_file  = run_dir + '/' + asp.ASP_REBOOT_FILE
    stop_file    = run_dir + '/' + asp.SAFPLUS_STOP_FILE
    asp.safe_remove(reboot_file)
    asp.remove_stop_file()
#    safe_remove(restart_disable_file) 
#    safe_remove(watchdog_restart_file)

    while True:
        try:
            pid = asp.get_amf_pid()
            if pid == 0:
                if os.path.isfile(stop_file):   # Kill watchdog if stop file exists        
                    print "Stop file exists: SAFplus is stopping"
                    return
                else:          # Restart AMF if stop file not found
                    print "Stop file not found: Starting AMF from Watchdog"
                    start_ams()
            wdSleep(SAFPLUS_RESTART_DELAY)
        except Exception, e:
            print "Exception %s" % str(e)
            pass 
def restart_asp():
    # remove no restart file, to make sure a restart occurs
    asp.remove_stop_file()
    asp.stop_amf()