Exemple #1
0
def launch_monitoring(args):
    es = ElasticReport(args=args)

    json_handler = FDJsonServer(es=es)
    env = os.environ.copy()
    env["DQM2_SOCKET"] = json_handler.fn 

    def preexec():
        try:
            # ensure the child dies if we are SIGKILLED
            import ctypes
            libc = ctypes.CDLL("libc.so.6")
            PR_SET_PDEATHSIG = 1
            libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
        except:
            log("Failed to setup PR_SET_PDEATHSIG.")
            pass

    p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True, env=env)
    CURRENT_PROC.append(p)

    zlog = None
    if args.zlog:
        try:
            relpath = os.path.dirname(__file__)
            sys.path.append(relpath)
            from ztee import GZipLog
            
            zlog_ = GZipLog(log_file=args.zlog)
            es.update_doc({ "stdlog_gzip": args.zlog })

            log("Open gzip log file: %s" % args.zlog)
            zlog = zlog_
        except Exception, e:
            log("Failed to setup zlog file: " + str(e))
Exemple #2
0
def launch_monitoring(args):
    es = ElasticReport(args=args)

    json_handler = FDJsonServer(es=es, args=args)
    env = os.environ.copy()
    env["DQM2_SOCKET"] = json_handler.fn

    def preexec():
        try:
            # ensure the child dies if we are SIGKILLED
            import ctypes
            libc = ctypes.CDLL("libc.so.6")
            PR_SET_PDEATHSIG = 1
            libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
        except:
            log("Failed to setup PR_SET_PDEATHSIG.")
            pass

    p = subprocess.Popen(args.pargs,
                         preexec_fn=preexec,
                         stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT,
                         close_fds=True,
                         env=env)
    CURRENT_PROC.append(p)

    zlog = None
    if args.zlog:
        try:
            relpath = os.path.dirname(__file__)
            sys.path.append(relpath)
            from ztee import GZipLog

            zlog_ = GZipLog(log_file=args.zlog)
            es.update_doc({"stdlog_gzip": args.zlog})

            log("Open gzip log file: %s" % args.zlog)
            zlog = zlog_
        except Exception as e:
            log("Failed to setup zlog file: " + str(e))

    es.update_doc({"pid": p.pid})
    es.update_doc({"monitoring_pid": os.getpid()})
    es.update_doc({"monitoring_socket": json_handler.fn})
    es.defaults()
    es.make_report()

    log_handler = FDOutputListener(fd=p.stdout.fileno(),
                                   es=es,
                                   zlog=zlog,
                                   close_socket=json_handler)
    log_handler.handle_line("-- starting process: %s --\n" % str(args.pargs))

    try:
        #manager.event_loop(timeout=5, exit_fd=p.stdout.fileno())
        asyncore.loop(timeout=5)
    except select.error as e:
        # we have this on ctrl+c
        # just terminate the child
        log("Select error (we will terminate): " + str(e))
        p.terminate()

    # at this point the program is dead
    r = p.wait()
    log_handler.handle_line("\n-- process exit: %s --\n" % str(r))
    log_handler.finish()

    es.update_doc({"exit_code": r})
    es.make_report()

    CURRENT_PROC.remove(p)
    return r