BUG/MINOR: mworker: reintroduce way to disable seamless reload with -x /dev/null

Since the introduction of the automatic seamless reload using the
internal socketpair, there is no way of disabling the seamless reload.

Previously we just needed to remove -x from the startup command line,
and remove any "expose-fd" keyword on stats socket lines.

This was introduced in 2be557f7c ("MEDIUM: mworker: seamless reload use
the internal sockpairs").

The patch copy /dev/null again and pass it to the next exec so we never
try to get socket from the -x.

Must be backported as far as 2.6.
This commit is contained in:
William Lallemand 2024-04-26 15:08:31 +02:00
parent e4a29447ce
commit 2ab42dddc4
2 changed files with 22 additions and 7 deletions

View File

@ -471,11 +471,16 @@ list of options is :
-x <unix_socket> : connect to the specified socket and try to retrieve any
listening sockets from the old process, and use them instead of trying to
bind new ones. This is useful to avoid missing any new connection when
reloading the configuration on Linux. The capability must be enable on the
stats socket using "expose-fd listeners" in your configuration.
In master-worker mode, the master will use this option upon a reload with
the "sockpair@" syntax, which allows the master to connect directly to a
worker without using stats socket declared in the configuration.
reloading the configuration on Linux.
Without master-worker mode, the capability must be enable on the stats
socket using "expose-fd listeners" in your configuration.
In master-worker mode, it does not need "expose-fd listeners", the master
will use automatically this option upon a reload with the "sockpair@"
syntax, which allows the master to connect directly to a worker without using
any stats socket declared in the configuration. If you want to disable this,
you can pass -x /dev/null.
A safe way to start HAProxy from an init file consists in forcing the daemon
mode, storing existing pids to a pid file and using this pid file to notify

View File

@ -721,6 +721,7 @@ static void mworker_reexec(int hardreload)
char *msg = NULL;
struct rlimit limit;
struct mworker_proc *current_child = NULL;
int x_off = 0; /* disable -x by putting -x /dev/null */
mworker_block_signals();
setenv("HAPROXY_MWORKER_REEXEC", "1", 1);
@ -768,6 +769,10 @@ static void mworker_reexec(int hardreload)
/* copy the program name */
next_argv[next_argc++] = old_argv[0];
/* we need to reintroduce /dev/null everytime */
if (old_unixsocket && strcmp(old_unixsocket, "/dev/null") == 0)
x_off = 1;
/* insert the new options just after argv[0] in case we have a -- */
if (getenv("HAPROXY_MWORKER_WAIT_ONLY") == NULL) {
@ -791,8 +796,7 @@ static void mworker_reexec(int hardreload)
msg = NULL;
}
}
if (current_child) {
if (!x_off && current_child) {
/* add the -x option with the socketpair of the current worker */
next_argv[next_argc++] = "-x";
if ((next_argv[next_argc++] = memprintf(&msg, "sockpair@%d", current_child->ipc_fd[0])) == NULL)
@ -801,6 +805,12 @@ static void mworker_reexec(int hardreload)
}
}
if (x_off) {
/* if the cmdline contained a -x /dev/null, continue to use it */
next_argv[next_argc++] = "-x";
next_argv[next_argc++] = "/dev/null";
}
/* copy the previous options */
for (i = 1; i < old_argc; i++)
next_argv[next_argc++] = old_argv[i];