summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_main_process.c
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2018-08-10 19:27:15 +0300
committerMax Romanov <max.romanov@nginx.com>2018-08-10 19:27:15 +0300
commitec1af823236a1863169bda14bc5c56ece11c73bb (patch)
tree04cccbbb492a4a8c81d87c34f6b84c935b40e448 /src/nxt_main_process.c
parent86740ab34b50190d8d6930565b23e8636518281f (diff)
downloadunit-ec1af823236a1863169bda14bc5c56ece11c73bb.tar.gz
unit-ec1af823236a1863169bda14bc5c56ece11c73bb.tar.bz2
Stopping all application processes if router process dies.
Unit master process restarts the router if the router accidentally dies. New router process receives the configuration from controller and starts configured applications. The information of running applications cannot be transferred to router because currently there is no persistent application identifier. To avoid orphan application processes started by died router, master process stops all currently running applications once it receives SIGCHLD for router process.
Diffstat (limited to '')
-rw-r--r--src/nxt_main_process.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/nxt_main_process.c b/src/nxt_main_process.c
index 27d17779..31e7ca9a 100644
--- a/src/nxt_main_process.c
+++ b/src/nxt_main_process.c
@@ -50,6 +50,7 @@ static void nxt_main_process_sigusr1_handler(nxt_task_t *task, void *obj,
static void nxt_main_process_sigchld_handler(nxt_task_t *task, void *obj,
void *data);
static void nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid);
+static void nxt_main_stop_worker_processes(nxt_task_t *task, nxt_runtime_t *rt);
static void nxt_main_port_socket_handler(nxt_task_t *task,
nxt_port_recv_msg_t *msg);
static nxt_int_t nxt_main_listening_socket(nxt_sockaddr_t *sa,
@@ -661,7 +662,7 @@ nxt_main_create_worker_process(nxt_task_t *task, nxt_runtime_t *rt,
void
-nxt_main_stop_worker_processes(nxt_task_t *task, nxt_runtime_t *rt)
+nxt_main_stop_all_processes(nxt_task_t *task, nxt_runtime_t *rt)
{
nxt_port_t *port;
nxt_process_t *process;
@@ -923,6 +924,10 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid)
} else if (init != NULL) {
if (init->restart != NULL) {
+ if (init->type == NXT_PROCESS_ROUTER) {
+ nxt_main_stop_worker_processes(task, rt);
+ }
+
init->restart(task, rt, init);
} else {
@@ -934,6 +939,27 @@ nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid)
static void
+nxt_main_stop_worker_processes(nxt_task_t *task, nxt_runtime_t *rt)
+{
+ nxt_port_t *port;
+ nxt_process_t *process;
+
+ nxt_runtime_process_each(rt, process) {
+
+ nxt_process_port_each(process, port) {
+
+ if (port->type == NXT_PROCESS_WORKER) {
+ (void) nxt_port_socket_write(task, port, NXT_PORT_MSG_QUIT,
+ -1, 0, 0, NULL);
+ }
+
+ } nxt_process_port_loop;
+
+ } nxt_runtime_process_loop;
+}
+
+
+static void
nxt_main_port_socket_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
{
size_t size;