MINOR: cli: "show version" displays the current process version
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 14 Dec 2021 14:22:29 +0000 (15:22 +0100)
committerWilliam Lallemand <wlallemand@haproxy.org>
Tue, 14 Dec 2021 14:49:06 +0000 (15:49 +0100)
This patch implements a simple "show version" command which returns
the version of the current process.

It's available from the master and the worker processes, so it is easy
to check if the master and the workers have the same version.

This is a minor patch that really improve compatibility checks
for scripts.

Could be backported in haproxy version as far as 2.0.

(cherry picked from commit 740629e2966641871b183d1c728fa7aeda45a1cc)
Signed-off-by: William Lallemand <wlallemand@haproxy.org>
(cherry picked from commit 02c2cc8cbec61287af9af54b7b712fdb5f9747ca)
Signed-off-by: William Lallemand <wlallemand@haproxy.org>
(cherry picked from commit 7ceae1189a8dce334c3078be0f9dffdb99f90c10)
[wla: context changes in cli.c]
Signed-off-by: William Lallemand <wlallemand@haproxy.org>

doc/management.txt
src/cli.c

index 11a1fca..996cbf4 100644 (file)
@@ -2818,6 +2818,17 @@ show trace [<source>]
   "-" otherwise. All these events are independent and an event might trigger
   a start without being reported and conversely.
 
+show version
+  Show the version of the current HAProxy process. This is available from
+  master and workers CLI.
+  Example:
+
+      $ echo "show version" | socat /var/run/haproxy.sock stdio
+      2.4.9
+
+      $ echo "show version" | socat /var/run/haproxy-master.sock stdio
+      2.5.0
+
 shutdown frontend <frontend>
   Completely delete the specified frontend. All the ports it was bound to will
   be released. It will not be possible to enable the frontend anymore after
index d53d518..daf48a2 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1586,6 +1586,13 @@ static int cli_parse_expert_mode(char **args, char *payload, struct appctx *appc
        return 1;
 }
 
+/* shows HAProxy version */
+static int cli_parse_show_version(char **args, char *payload, struct appctx *appctx, void *private)
+{
+       char *msg = NULL;
+
+       return cli_dynmsg(appctx, LOG_INFO, memprintf(&msg, "%s\n", haproxy_version));
+}
 
 int cli_parse_default(char **args, char *payload, struct appctx *appctx, void *private)
 {
@@ -2818,6 +2825,7 @@ static struct cli_kw_list cli_kws = {{ },{
        { { "show", "cli", "level", NULL },    "show cli level   : display the level of the current CLI session", cli_parse_show_lvl, NULL, NULL, NULL, ACCESS_MASTER},
        { { "show", "fd", NULL }, "show fd [num] : dump list of file descriptors in use", cli_parse_show_fd, cli_io_handler_show_fd, NULL },
        { { "show", "activity", NULL }, "show activity : show per-thread activity stats (for support/developers)", cli_parse_default, cli_io_handler_show_activity, NULL },
+       { { "show", "version", NULL },  "show version  : show version of the current process", cli_parse_show_version, NULL, NULL, NULL, ACCESS_MASTER },
        { { "operator", NULL },  "operator       : lower the level of the current CLI session to operator", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
        { { "user", NULL },      "user           : lower the level of the current CLI session to user", cli_parse_set_lvl, NULL, NULL, NULL, ACCESS_MASTER},
        { { "_getsocks", NULL }, NULL,  _getsocks, NULL },