]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: export localpeer as an environment variable
authorWilliam Lallemand <wlallemand@haproxy.com>
Tue, 17 Apr 2018 14:46:13 +0000 (16:46 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Apr 2018 15:17:58 +0000 (17:17 +0200)
Export localpeer as the environment variable $HAPROXY_LOCALPEER,
allowing to use this variable in the configuration file.

It's useful to use this variable in the case of synchronized
configuration between peers.

doc/configuration.txt
doc/management.txt
src/haproxy.c

index c6877226bad6a59bbd12d4b3b34cd4178659f0c5..dcc87fdc09ea5a86c99ae2e1155b7d06cd82e3b3 100644 (file)
@@ -476,6 +476,9 @@ underscore ("_") but should not start with a digit.
 
       user "$HAPROXY_USER"
 
+A special variable $HAPROXY_LOCALPEER is defined at the startup of the process
+which contains the name of the local peer. (See "-L" in the management guide.)
+
 
 2.4. Time format
 ----------------
index 1488862e709e6aeb4095c93f12b98bf0546a810a..4b6901851179d7351eeb5a2d9783b2cc88311326 100644 (file)
@@ -161,7 +161,9 @@ list of options is :
     that a faulty configuration doesn't prevent the system from booting.
 
   -L <name> : change the local peer name to <name>, which defaults to the local
-    hostname. This is used only with peers replication.
+    hostname. This is used only with peers replication. You can use the
+    variable $HAPROXY_LOCALPEER in the configuration file to reference the
+    peer name.
 
   -N <limit> : sets the default per-proxy maxconn to <limit> instead of the
     builtin default value (usually 2000). Only useful for debugging.
index d5235ebaf184f1f74d36943f37702889acf95c64..48a77e8f37c7662d1331be5c6fb5da928282d8b9 100644 (file)
@@ -1293,6 +1293,7 @@ static void init(int argc, char **argv)
        gethostname(hostname, sizeof(hostname) - 1);
        memset(localpeer, 0, sizeof(localpeer));
        memcpy(localpeer, hostname, (sizeof(hostname) > sizeof(localpeer) ? sizeof(localpeer) : sizeof(hostname)) - 1);
+       setenv("HAPROXY_LOCALPEER", localpeer, 1);
 
        /*
         * Initialize the previously static variables.
@@ -1496,7 +1497,10 @@ static void init(int argc, char **argv)
                                case 'n' : cfg_maxconn = atol(*argv); break;
                                case 'm' : global.rlimit_memmax_all = atol(*argv); break;
                                case 'N' : cfg_maxpconn = atol(*argv); break;
-                               case 'L' : strncpy(localpeer, *argv, sizeof(localpeer) - 1); break;
+                               case 'L' :
+                                       strncpy(localpeer, *argv, sizeof(localpeer) - 1);
+                                       setenv("HAPROXY_LOCALPEER", localpeer, 1);
+                                       break;
                                case 'f' :
                                        if (!list_append_word(&cfg_cfgfiles, *argv, &err_msg)) {
                                                ha_alert("Cannot load configuration file/directory %s : %s\n",