haproxy/include/haproxy/mworker.h
Valentine Krasnobaeva b73a278df4 MINOR: mworker/cli: add _send_status to support state transition
In the new master-worker architecture, when a worker process is forked and
successfully initialized it needs somehow to communicate its "READY" state to
the master, in order to terminate the previous worker and workers, that might
exceeded max_reloads counter.

So, let's implement for this a new master CLI _send_status command. A new
worker can send its status string "READY" to the master, when it's about
entering to the run poll loop, thus it can start to receive data.

In _send_status() in the master context we update the status of the new worker:
PROC_O_INIT flag is withdrawn.

When TERM signal is sent to a worker, worker terminates and this triggers the
mworker_catch_sigchld() handler in master. This handler deletes the exiting
process entry from the processes list.

In _send_status() we loop over the processes list twice. At the first time, in
order to stop workers that exceeded the max_reloads counter. At the second time,
in order to stop the worker forked before the last reload. In the corner case,
when max_reloads=1, we avoid to send SIGTERM twice to the same worker by
setting sigterm_sent flag during the first loop.
2024-10-16 22:02:39 +02:00

54 lines
1.4 KiB
C

/*
* include/haproxy/mworker-t.h
* Master Worker function prototypes.
*
* Copyright HAProxy Technologies 2019 - William Lallemand <wlallemand@haproxy.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
*/
#ifndef _HAPROXY_MWORKER_H_
#define _HAPROXY_MWORKER_H_
#include <haproxy/mworker-t.h>
#include <haproxy/signal-t.h>
extern int max_reloads;
extern struct mworker_proc *proc_self;
/* master CLI configuration (-S flag) */
extern struct list mworker_cli_conf;
void mworker_proc_list_to_env(void);
int mworker_env_to_proc_list(void);
void mworker_block_signals(void);
void mworker_unblock_signals(void);
void mworker_broadcast_signal(struct sig_handler *sh);
void mworker_catch_sighup(struct sig_handler *sh);
void mworker_catch_sigterm(struct sig_handler *sh);
void mworker_catch_sigchld(struct sig_handler *sh);
void mworker_accept_wrapper(int fd);
void mworker_cleanlisteners(void);
int mworker_child_nb(void);
int mworker_ext_launch_all(void);
void mworker_kill_max_reloads(int sig);
struct mworker_proc *mworker_proc_new();
void mworker_free_child(struct mworker_proc *);
void mworker_cleanup_proc();
void mworker_create_master_cli(void);
#endif /* _HAPROXY_MWORKER_H_ */