393 env = os.environ.copy()
394 env[
"DQM2_SOCKET"] = json_handler.fn
400 libc = ctypes.CDLL(
"libc.so.6")
402 libc.prctl(PR_SET_PDEATHSIG, signal.SIGKILL)
404 log(
"Failed to setup PR_SET_PDEATHSIG.")
407 p = subprocess.Popen(args.pargs, preexec_fn=preexec, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=
True, env=env)
408 CURRENT_PROC.append(p)
413 relpath = os.path.dirname(__file__)
414 sys.path.append(relpath)
415 from ztee
import GZipLog
417 zlog_ = GZipLog(log_file=args.zlog)
418 es.update_doc({
"stdlog_gzip": args.zlog })
420 log(
"Open gzip log file: %s" % args.zlog)
422 except Exception
as e:
423 log(
"Failed to setup zlog file: " +
str(e))
425 es.update_doc({
"pid": p.pid })
426 es.update_doc({
"monitoring_pid": os.getpid() })
427 es.update_doc({
"monitoring_socket": json_handler.fn })
431 log_handler =
FDOutputListener(fd=p.stdout.fileno(), es=es, zlog=zlog, close_socket=json_handler)
432 log_handler.handle_line(
"-- starting process: %s --\n" %
str(args.pargs))
436 asyncore.loop(timeout=5)
437 except select.error
as e:
440 log(
"Select error (we will terminate): " +
str(e))
445 log_handler.handle_line(
"\n-- process exit: %s --\n" %
str(r))
448 es.update_doc({
"exit_code": r })
451 CURRENT_PROC.remove(p)