392 env = os.environ.copy()
393 env[
"DQM2_SOCKET"] = json_handler.fn
399 libc = ctypes.CDLL(
"libc.so.6")
401 libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
403 log(
"Failed to setup PR_SET_PDEATHSIG.")
406 p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True, env=env)
407 CURRENT_PROC.append(p)
412 relpath = os.path.dirname(__file__)
413 sys.path.append(relpath)
414 from ztee
import GZipLog
416 zlog_ = GZipLog(log_file=args.zlog)
417 es.update_doc({
"stdlog_gzip": args.zlog })
419 log(
"Open gzip log file: %s" % args.zlog)
421 except Exception
as e:
422 log(
"Failed to setup zlog file: " + str(e))
424 es.update_doc({
"pid": p.pid })
425 es.update_doc({
"monitoring_pid": os.getpid() })
426 es.update_doc({
"monitoring_socket": json_handler.fn })
430 log_handler =
FDOutputListener(fd=p.stdout.fileno(), es=es, zlog=zlog, close_socket=json_handler)
431 log_handler.handle_line(
"-- starting process: %s --\n" % str(args.pargs))
435 asyncore.loop(timeout=5)
436 except select.error
as e:
439 log(
"Select error (we will terminate): " + str(e))
444 log_handler.handle_line(
"\n-- process exit: %s --\n" % str(r))
447 es.update_doc({
"exit_code": r })
450 CURRENT_PROC.remove(p)