MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
/*
|
|
|
|
* Wrapper to make haproxy systemd-compliant.
|
|
|
|
*
|
|
|
|
* Copyright 2013 Marc-Antoine Perennou <Marc-Antoine@Perennou.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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2014-04-17 13:39:28 +00:00
|
|
|
#define REEXEC_FLAG "HAPROXY_SYSTEMD_REEXEC"
|
2014-04-17 13:39:29 +00:00
|
|
|
#define SD_DEBUG "<7>"
|
|
|
|
#define SD_NOTICE "<5>"
|
2014-04-17 13:39:28 +00:00
|
|
|
|
2014-07-28 21:52:20 +00:00
|
|
|
static volatile sig_atomic_t caught_signal;
|
|
|
|
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
static char *pid_file = "/run/haproxy.pid";
|
2014-04-17 13:39:28 +00:00
|
|
|
static int wrapper_argc;
|
|
|
|
static char **wrapper_argv;
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
|
2014-09-19 13:42:30 +00:00
|
|
|
/* returns the path to the haproxy binary into <buffer>, whose size indicated
|
|
|
|
* in <buffer_size> must be at least 1 byte long.
|
|
|
|
*/
|
2013-11-22 10:06:34 +00:00
|
|
|
static void locate_haproxy(char *buffer, size_t buffer_size)
|
|
|
|
{
|
2014-04-14 13:34:34 +00:00
|
|
|
char *end = NULL;
|
2014-09-19 13:42:30 +00:00
|
|
|
int len;
|
|
|
|
|
|
|
|
len = readlink("/proc/self/exe", buffer, buffer_size - 1);
|
|
|
|
if (len == -1)
|
|
|
|
goto fail;
|
2014-04-14 13:34:34 +00:00
|
|
|
|
2014-09-19 13:42:30 +00:00
|
|
|
buffer[len] = 0;
|
|
|
|
end = strrchr(buffer, '/');
|
|
|
|
if (end == NULL)
|
|
|
|
goto fail;
|
2014-04-14 13:34:34 +00:00
|
|
|
|
2014-09-19 13:42:30 +00:00
|
|
|
if (strcmp(end + strlen(end) - 16, "-systemd-wrapper") == 0) {
|
|
|
|
end[strlen(end) - 16] = '\0';
|
2014-04-14 13:34:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-09-19 13:42:30 +00:00
|
|
|
|
2013-11-22 10:06:34 +00:00
|
|
|
end[1] = '\0';
|
2014-04-14 13:34:34 +00:00
|
|
|
strncpy(end + 1, "haproxy", buffer + buffer_size - (end + 1));
|
|
|
|
buffer[buffer_size - 1] = '\0';
|
2014-09-19 13:42:30 +00:00
|
|
|
return;
|
|
|
|
fail:
|
|
|
|
strncpy(buffer, "/usr/sbin/haproxy", buffer_size);
|
|
|
|
buffer[buffer_size - 1] = '\0';
|
|
|
|
return;
|
2013-11-22 10:06:34 +00:00
|
|
|
}
|
|
|
|
|
2013-04-02 11:53:21 +00:00
|
|
|
static void spawn_haproxy(char **pid_strv, int nb_pid)
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
{
|
2013-11-22 10:06:34 +00:00
|
|
|
char haproxy_bin[512];
|
|
|
|
pid_t pid;
|
2014-04-17 13:39:28 +00:00
|
|
|
int main_argc;
|
|
|
|
char **main_argv;
|
|
|
|
|
|
|
|
main_argc = wrapper_argc - 1;
|
|
|
|
main_argv = wrapper_argv + 1;
|
2013-11-22 10:06:34 +00:00
|
|
|
|
2014-09-24 10:59:25 +00:00
|
|
|
pid = fork();
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
if (!pid) {
|
|
|
|
/* 3 for "haproxy -Ds -sf" */
|
|
|
|
char **argv = calloc(4 + main_argc + nb_pid + 1, sizeof(char *));
|
|
|
|
int i;
|
|
|
|
int argno = 0;
|
2013-11-22 10:06:34 +00:00
|
|
|
locate_haproxy(haproxy_bin, 512);
|
|
|
|
argv[argno++] = haproxy_bin;
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
for (i = 0; i < main_argc; ++i)
|
|
|
|
argv[argno++] = main_argv[i];
|
|
|
|
argv[argno++] = "-Ds";
|
|
|
|
if (nb_pid > 0) {
|
|
|
|
argv[argno++] = "-sf";
|
|
|
|
for (i = 0; i < nb_pid; ++i)
|
|
|
|
argv[argno++] = pid_strv[i];
|
|
|
|
}
|
|
|
|
argv[argno] = NULL;
|
2013-11-22 10:11:54 +00:00
|
|
|
|
2014-04-17 13:39:29 +00:00
|
|
|
fprintf(stderr, SD_DEBUG "haproxy-systemd-wrapper: executing ");
|
2013-11-22 10:11:54 +00:00
|
|
|
for (i = 0; argv[i]; ++i)
|
2014-04-17 13:39:29 +00:00
|
|
|
fprintf(stderr, "%s ", argv[i]);
|
|
|
|
fprintf(stderr, "\n");
|
2013-11-22 10:11:54 +00:00
|
|
|
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
execv(argv[0], argv);
|
2016-10-25 13:50:47 +00:00
|
|
|
exit(1);
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int read_pids(char ***pid_strv)
|
|
|
|
{
|
|
|
|
FILE *f = fopen(pid_file, "r");
|
|
|
|
int read = 0, allocated = 8;
|
|
|
|
char pid_str[10];
|
|
|
|
|
|
|
|
if (!f)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
*pid_strv = malloc(allocated * sizeof(char *));
|
|
|
|
while (1 == fscanf(f, "%s\n", pid_str)) {
|
|
|
|
if (read == allocated) {
|
|
|
|
allocated *= 2;
|
|
|
|
*pid_strv = realloc(*pid_strv, allocated * sizeof(char *));
|
|
|
|
}
|
|
|
|
(*pid_strv)[read++] = strdup(pid_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(f);
|
|
|
|
|
|
|
|
return read;
|
|
|
|
}
|
|
|
|
|
2014-07-28 21:52:20 +00:00
|
|
|
static void signal_handler(int signum)
|
|
|
|
{
|
2016-02-27 07:26:14 +00:00
|
|
|
if (caught_signal != SIGINT && caught_signal != SIGTERM)
|
|
|
|
caught_signal = signum;
|
2014-07-28 21:52:20 +00:00
|
|
|
}
|
|
|
|
|
2016-02-27 07:18:04 +00:00
|
|
|
/* handles SIGUSR2 and SIGHUP only */
|
|
|
|
static void do_restart(int sig)
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
{
|
2014-04-17 13:39:28 +00:00
|
|
|
setenv(REEXEC_FLAG, "1", 1);
|
2016-02-27 07:18:04 +00:00
|
|
|
fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: re-executing on %s.\n",
|
|
|
|
sig == SIGUSR2 ? "SIGUSR2" : "SIGHUP");
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
|
2014-04-17 13:39:28 +00:00
|
|
|
execv(wrapper_argv[0], wrapper_argv);
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
}
|
|
|
|
|
2016-02-27 07:18:04 +00:00
|
|
|
/* handles SIGTERM and SIGINT only */
|
|
|
|
static void do_shutdown(int sig)
|
2013-11-22 10:09:39 +00:00
|
|
|
{
|
|
|
|
int i, pid;
|
|
|
|
char **pid_strv = NULL;
|
|
|
|
int nb_pid = read_pids(&pid_strv);
|
|
|
|
for (i = 0; i < nb_pid; ++i) {
|
|
|
|
pid = atoi(pid_strv[i]);
|
|
|
|
if (pid > 0) {
|
2016-02-27 07:18:04 +00:00
|
|
|
fprintf(stderr, SD_DEBUG "haproxy-systemd-wrapper: %s -> %d.\n",
|
|
|
|
sig == SIGTERM ? "SIGTERM" : "SIGINT", pid);
|
2016-02-27 07:20:17 +00:00
|
|
|
kill(pid, sig);
|
2013-11-22 10:09:39 +00:00
|
|
|
free(pid_strv[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(pid_strv);
|
|
|
|
}
|
|
|
|
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
static void init(int argc, char **argv)
|
|
|
|
{
|
|
|
|
while (argc > 1) {
|
2014-07-28 21:22:43 +00:00
|
|
|
if ((*argv)[0] == '-' && (*argv)[1] == 'p') {
|
|
|
|
pid_file = *(argv + 1);
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
}
|
|
|
|
--argc; ++argv;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2013-11-22 10:11:54 +00:00
|
|
|
int status;
|
2015-03-03 22:26:14 +00:00
|
|
|
struct sigaction sa;
|
2013-11-22 10:11:54 +00:00
|
|
|
|
2014-04-17 13:39:28 +00:00
|
|
|
wrapper_argc = argc;
|
|
|
|
wrapper_argv = argv;
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
|
2014-04-17 13:39:28 +00:00
|
|
|
--argc; ++argv;
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
init(argc, argv);
|
|
|
|
|
2014-07-28 21:52:20 +00:00
|
|
|
memset(&sa, 0, sizeof(struct sigaction));
|
|
|
|
sa.sa_handler = &signal_handler;
|
|
|
|
sigaction(SIGUSR2, &sa, NULL);
|
2014-09-11 05:19:30 +00:00
|
|
|
sigaction(SIGHUP, &sa, NULL);
|
2014-07-28 21:52:20 +00:00
|
|
|
sigaction(SIGINT, &sa, NULL);
|
2014-09-11 05:19:30 +00:00
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
|
2014-04-17 13:39:28 +00:00
|
|
|
if (getenv(REEXEC_FLAG) != NULL) {
|
|
|
|
/* We are being re-executed: restart HAProxy gracefully */
|
|
|
|
int i;
|
|
|
|
char **pid_strv = NULL;
|
|
|
|
int nb_pid = read_pids(&pid_strv);
|
|
|
|
|
|
|
|
unsetenv(REEXEC_FLAG);
|
|
|
|
spawn_haproxy(pid_strv, nb_pid);
|
|
|
|
|
|
|
|
for (i = 0; i < nb_pid; ++i)
|
|
|
|
free(pid_strv[i]);
|
|
|
|
free(pid_strv);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* Start a fresh copy of HAProxy */
|
|
|
|
spawn_haproxy(NULL, 0);
|
|
|
|
}
|
|
|
|
|
2013-11-22 10:11:54 +00:00
|
|
|
status = -1;
|
2016-02-27 06:58:50 +00:00
|
|
|
while (caught_signal || wait(&status) != -1 || errno == EINTR) {
|
2016-02-27 07:18:04 +00:00
|
|
|
int sig = caught_signal;
|
|
|
|
|
2014-09-11 05:19:30 +00:00
|
|
|
if (caught_signal == SIGUSR2 || caught_signal == SIGHUP) {
|
2014-07-28 21:52:20 +00:00
|
|
|
caught_signal = 0;
|
2016-02-27 07:18:04 +00:00
|
|
|
do_restart(sig);
|
2014-07-28 21:52:20 +00:00
|
|
|
}
|
2014-09-11 05:19:30 +00:00
|
|
|
else if (caught_signal == SIGINT || caught_signal == SIGTERM) {
|
2014-07-28 21:52:20 +00:00
|
|
|
caught_signal = 0;
|
2016-02-27 07:18:04 +00:00
|
|
|
do_shutdown(sig);
|
2014-07-28 21:52:20 +00:00
|
|
|
}
|
|
|
|
}
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
|
2014-04-17 13:39:29 +00:00
|
|
|
fprintf(stderr, SD_NOTICE "haproxy-systemd-wrapper: exit, haproxy RC=%d\n",
|
|
|
|
status);
|
2014-04-17 13:39:30 +00:00
|
|
|
return status;
|
MEDIUM: add haproxy-systemd-wrapper
Currently, to reload haproxy configuration, you have to use "-sf".
There is a problem with this way of doing things. First of all, in the systemd world,
reload commands should be "oneshot" ones, which means they should not be the new main
process but rather a tool which makes a call to it and then exits. With the current approach,
the reload command is the new main command and moreover, it makes the previous one exit.
Systemd only tracks the main program, seeing it ending, it assumes it either finished or failed,
and kills everything remaining as a grabage collector. We then end up with no haproxy running
at all.
This patch adds wrapper around haproxy, no changes at all have been made into it,
so it's not intrusive and doesn't change anything for other hosts. What this wrapper does
is basically launching haproxy as a child, listen to the SIGUSR2 (not to conflict with
haproxy itself) signal, and spawing a new haproxy with "-sf" as a child to relay the
first one.
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2013-02-12 09:53:53 +00:00
|
|
|
}
|