From 9f770fec367e252a45bfe2ee4fd16c80344f69e1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sat, 21 May 2016 10:42:09 +0900 Subject: [PATCH] nghttpx: Save PID file after it is ready to accept connections --- src/shrpx.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/shrpx.cc b/src/shrpx.cc index 0534d739..621e691f 100644 --- a/src/shrpx.cc +++ b/src/shrpx.cc @@ -946,10 +946,6 @@ int event_loop() { redirect_stderr_to_errorlog(); } - if (!get_config()->pid_file.empty()) { - save_pid(); - } - SignalServer ssv; rv = pipe(ssv.ipc_fd.data()); @@ -996,6 +992,14 @@ int event_loop() { worker_process_childev.data = nullptr; ev_child_start(loop, &worker_process_childev); + // Write PID file when we are ready to accept connection from peer. + // This makes easier to write restart script for nghttpx. Because + // when we know that PID file is recreated, it means we can send + // QUIT signal to the old process to make it shutdown gracefully. + if (!get_config()->pid_file.empty()) { + save_pid(); + } + ev_run(loop, 0); return 0;