From: William Lallemand Date: Wed, 10 Nov 2021 09:49:06 +0000 (+0100) Subject: MINOR: mworker: implement a reload failure counter X-Git-Tag: v2.5-dev14~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68836740;p=thirdparty%2Fhaproxy.git MINOR: mworker: implement a reload failure counter Implement a reload failure counter which counts the number of failure since the last success. This counter is available in 'show proc' over the master CLI. --- diff --git a/include/haproxy/mworker-t.h b/include/haproxy/mworker-t.h index dabdf810a6..3137ec0be9 100644 --- a/include/haproxy/mworker-t.h +++ b/include/haproxy/mworker-t.h @@ -40,6 +40,7 @@ struct mworker_proc { char *version; int ipc_fd[2]; /* 0 is master side, 1 is worker side */ int reloads; + int failedreloads; /* number of failed reloads since the last successful one */ int timestamp; struct server *srv; /* the server entry in the master proxy */ struct list list; diff --git a/src/haproxy.c b/src/haproxy.c index a6b8dc3adf..187ba750ae 100644 --- a/src/haproxy.c +++ b/src/haproxy.c @@ -864,8 +864,21 @@ static void mworker_loop() */ void reexec_on_failure() { + struct mworker_proc *child; + if (!atexit_flag) return; + + /* get the info of the children in the env */ + if (mworker_env_to_proc_list() < 0) { + exit(EXIT_FAILURE); + } + + /* increment the number of failed reloads */ + list_for_each_entry(child, &proc_list, list) { + child->failedreloads++; + } + usermsgs_clr(NULL); ha_warning("Loading failure!\n"); mworker_reexec_waitmode(); @@ -1945,6 +1958,7 @@ static void init(int argc, char **argv) exit(EXIT_FAILURE); } tmproc->options |= PROC_O_TYPE_MASTER; /* master */ + tmproc->failedreloads = 0; tmproc->reloads = 0; tmproc->pid = pid; tmproc->timestamp = start_date.tv_sec; @@ -1964,6 +1978,7 @@ static void init(int argc, char **argv) tmproc->options |= PROC_O_TYPE_WORKER; /* worker */ tmproc->pid = -1; + tmproc->failedreloads = 0; tmproc->reloads = 0; tmproc->timestamp = -1; tmproc->ipc_fd[0] = -1; @@ -3268,6 +3283,7 @@ int main(int argc, char **argv) /* if not in wait mode, reload in wait mode to free the memory */ ha_notice("Loading success.\n"); + proc_self->failedreloads = 0; /* reset the number of failure */ mworker_reexec_waitmode(); } /* should never get there */ diff --git a/src/mworker.c b/src/mworker.c index fe1770618b..a14a840938 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -122,7 +122,7 @@ void mworker_proc_list_to_env() type = 'w'; if (child->pid > -1) - memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;reloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->reloads, child->timestamp, child->id ? child->id : "", child->version); + memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;reloads=%d;failedreloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->reloads, child->failedreloads, child->timestamp, child->id ? child->id : "", child->version); } if (msg) setenv("HAPROXY_PROCESSES", msg, 1); @@ -176,6 +176,8 @@ int mworker_env_to_proc_list() } else if (strncmp(subtoken, "reloads=", 8) == 0) { /* we only increment the number of asked reload */ child->reloads = atoi(subtoken+8); + } else if (strncmp(subtoken, "failedreloads=", 14) == 0) { + child->failedreloads = atoi(subtoken+14); } else if (strncmp(subtoken, "timestamp=", 10) == 0) { child->timestamp = atoi(subtoken+10); } else if (strncmp(subtoken, "id=", 3) == 0) { @@ -455,15 +457,18 @@ static int cli_io_handler_show_proc(struct appctx *appctx) int old = 0; int up = now.tv_sec - proc_self->timestamp; char *uptime = NULL; + char *reloadtxt = NULL; if (unlikely(si_ic(si)->flags & (CF_WRITE_ERROR|CF_SHUTW))) return 1; chunk_reset(&trash); + memprintf(&reloadtxt, "%d [failed: %d]", proc_self->reloads, proc_self->failedreloads); chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "", "", "", "", ""); memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60)); - chunk_appendf(&trash, "%-15u %-15s %-15d %-15s %-15s\n", (unsigned int)getpid(), "master", proc_self->reloads, uptime, haproxy_version); + chunk_appendf(&trash, "%-15u %-15s %-15s %-15s %-15s\n", (unsigned int)getpid(), "master", reloadtxt, uptime, haproxy_version); + ha_free(&reloadtxt); ha_free(&uptime); /* displays current processes */