]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mworker: add the HAProxy version in "show proc"
authorWilliam Lallemand <wlallemand@haproxy.com>
Wed, 12 Jun 2019 17:11:33 +0000 (19:11 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Wed, 12 Jun 2019 17:19:57 +0000 (19:19 +0200)
Displays the HAProxy version so you can compare the version of old
processes and new ones.

doc/management.txt
include/types/global.h
src/haproxy.c
src/mworker.c

index 7cc1d75f9e32472efe26c4069c02c9f377301efe..616a040b7ddb603de9dc2d9d0737aa9d832ab536 100644 (file)
@@ -2612,13 +2612,13 @@ processes:
 Example:
 
   $ echo 'show proc' | socat /var/run/haproxy-master.sock -
-  #<PID>          <type>          <relative PID>  <reloads>       <uptime>
-  1162            master          0               5               0d 00h02m07s
+  #<PID>          <type>          <relative PID>  <reloads>       <uptime>        <version>
+  1162            master          0               5               0d00h02m07s     2.0-dev7-0124c9-7
   # workers
-  1271            worker          1               0               0d 00h00m00s
-  1272            worker          2               0               0d 00h00m00s
+  1271            worker          1               0               0d00h00m00s     2.0-dev7-0124c9-7
+  1272            worker          2               0               0d00h00m00s     2.0-dev7-0124c9-7
   # old workers
-  1233            worker          [was: 1]        3               0d 00h00m43s
+  1233            worker          [was: 1]        3               0d00h00m43s     2.0-dev3-6019f6-289
 
 
 In this example, the master has been reloaded 5 times but one of the old
index 5fca648af22020a9c7ad7b737333e82a3aba2f66..f9ab4c29d34f1e12b65044c9d359ab56c45bdc16 100644 (file)
@@ -208,6 +208,7 @@ struct mworker_proc {
        char *id;
        char **command;
        char *path;
+       char *version;
        int ipc_fd[2]; /* 0 is master side, 1 is worker side */
        int relative_pid;
        int reloads;
index c9370a3231a4620621a492790b930a2fbecf70ab..0c1d5a2636dfb201713fac83030869751eaeff11 100644 (file)
@@ -3039,6 +3039,7 @@ int main(int argc, char **argv)
                                                    child->reloads == 0 && child->options & PROC_O_TYPE_WORKER) {
                                                        child->timestamp = now.tv_sec;
                                                        child->pid = ret;
+                                                       child->version = strdup(haproxy_version);
                                                        break;
                                                }
                                        }
index cd88723536755c7d1ef37ca0b659ca0be4954599..6a4f1f57555f1f435cf414b8e030011a01e5e738 100644 (file)
@@ -20,6 +20,7 @@
 #include <common/cfgparse.h>
 #include <common/initcall.h>
 #include <common/mini-clist.h>
+#include <common/version.h>
 
 #include <types/cli.h>
 #include <types/global.h>
@@ -121,7 +122,7 @@ void mworker_proc_list_to_env()
                        type = 'w';
 
                if (child->pid > -1)
-                       memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d;id=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp, child->id ? child->id : "");
+                       memprintf(&msg, "%s|type=%c;fd=%d;pid=%d;rpid=%d;reloads=%d;timestamp=%d;id=%s;version=%s", msg ? msg : "", type, child->ipc_fd[0], child->pid, child->relative_pid, child->reloads, child->timestamp, child->id ? child->id : "", child->version);
        }
        if (msg)
                setenv("HAPROXY_PROCESSES", msg, 1);
@@ -177,6 +178,8 @@ void mworker_env_to_proc_list()
                                child->timestamp = atoi(subtoken+10);
                        } else if (strncmp(subtoken, "id=", 3) == 0) {
                                child->id = strdup(subtoken+3);
+                       } else if (strncmp(subtoken, "version=", 8) == 0) {
+                               child->version = strdup(subtoken+8);
                        }
                }
                if (child->pid) {
@@ -444,9 +447,9 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
 
        chunk_reset(&trash);
 
-       chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>");
+       chunk_printf(&trash, "#%-14s %-15s %-15s %-15s %-15s %-15s\n", "<PID>", "<type>", "<relative PID>", "<reloads>", "<uptime>", "<version>");
        memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-       chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime);
+       chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", getpid(), "master", 0, proc_self->reloads, uptime, haproxy_version);
        free(uptime);
        uptime = NULL;
 
@@ -464,7 +467,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
                        continue;
                }
                memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-               chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime);
+               chunk_appendf(&trash, "%-15u %-15s %-15u %-15d %-15s %-15s\n", child->pid, "worker", child->relative_pid, child->reloads, uptime, child->version);
                free(uptime);
                uptime = NULL;
        }
@@ -484,7 +487,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
                        if (child->options & PROC_O_LEAVING) {
                                memprintf(&msg, "[was: %u]", child->relative_pid);
                                memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, "worker", msg, child->reloads, uptime);
+                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, "worker", msg, child->reloads, uptime, child->version);
                                free(uptime);
                                uptime = NULL;
                        }
@@ -506,7 +509,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
                        continue;
                }
                memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime);
+               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-");
                free(uptime);
                uptime = NULL;
        }
@@ -521,7 +524,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx)
 
                        if (child->options & PROC_O_LEAVING) {
                                memprintf(&uptime, "%dd%02dh%02dm%02ds", up / 86400, (up % 86400) / 3600, (up % 3600) / 60, (up % 60));
-                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s\n", child->pid, child->id, "-", child->reloads, uptime);
+                               chunk_appendf(&trash, "%-15u %-15s %-15s %-15d %-15s %-15s\n", child->pid, child->id, "-", child->reloads, uptime, "-");
                                free(uptime);
                                uptime = NULL;
                        }
@@ -599,6 +602,10 @@ void mworker_free_child(struct mworker_proc *child)
                free(child->id);
                child->id = NULL;
        }
+       if (child->version) {
+               free(child->version);
+               child->version = NULL;
+       }
        free(child);
 }