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.
This commit is contained in:
parent
86740ab34b
commit
ec1af82323
3 changed files with 29 additions and 3 deletions
|
@ -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,
|
static void nxt_main_process_sigchld_handler(nxt_task_t *task, void *obj,
|
||||||
void *data);
|
void *data);
|
||||||
static void nxt_main_cleanup_worker_process(nxt_task_t *task, nxt_pid_t pid);
|
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,
|
static void nxt_main_port_socket_handler(nxt_task_t *task,
|
||||||
nxt_port_recv_msg_t *msg);
|
nxt_port_recv_msg_t *msg);
|
||||||
static nxt_int_t nxt_main_listening_socket(nxt_sockaddr_t *sa,
|
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
|
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_port_t *port;
|
||||||
nxt_process_t *process;
|
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) {
|
} else if (init != NULL) {
|
||||||
if (init->restart != NULL) {
|
if (init->restart != NULL) {
|
||||||
|
if (init->type == NXT_PROCESS_ROUTER) {
|
||||||
|
nxt_main_stop_worker_processes(task, rt);
|
||||||
|
}
|
||||||
|
|
||||||
init->restart(task, rt, init);
|
init->restart(task, rt, init);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -933,6 +938,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
|
static void
|
||||||
nxt_main_port_socket_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
nxt_main_port_socket_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,7 +21,7 @@ typedef enum {
|
||||||
|
|
||||||
nxt_int_t nxt_main_process_start(nxt_thread_t *thr, nxt_task_t *task,
|
nxt_int_t nxt_main_process_start(nxt_thread_t *thr, nxt_task_t *task,
|
||||||
nxt_runtime_t *runtime);
|
nxt_runtime_t *runtime);
|
||||||
void nxt_main_stop_worker_processes(nxt_task_t *task, nxt_runtime_t *runtime);
|
void nxt_main_stop_all_processes(nxt_task_t *task, nxt_runtime_t *runtime);
|
||||||
|
|
||||||
nxt_int_t nxt_controller_start(nxt_task_t *task, void *data);
|
nxt_int_t nxt_controller_start(nxt_task_t *task, void *data);
|
||||||
nxt_int_t nxt_router_start(nxt_task_t *task, void *data);
|
nxt_int_t nxt_router_start(nxt_task_t *task, void *data);
|
||||||
|
|
|
@ -435,7 +435,7 @@ nxt_runtime_quit(nxt_task_t *task, nxt_uint_t status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rt->type == NXT_PROCESS_MAIN) {
|
if (rt->type == NXT_PROCESS_MAIN) {
|
||||||
nxt_main_stop_worker_processes(task, rt);
|
nxt_main_stop_all_processes(task, rt);
|
||||||
done = 0;
|
done = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue