MEDIUM: peers: add the "localpeer" global option

localpeer <name>
  Sets the local instance's peer name. It will be ignored if the "-L"
  command line argument is specified or if used after "peers" section
  definitions. In such cases, a warning message will be emitted during
  the configuration parsing.

  This option will also set the HAPROXY_LOCALPEER environment variable.
  See also "-L" in the management guide and "peers" section in the
  configuration manual.
diff --git a/doc/configuration.txt b/doc/configuration.txt
index cddd70f..0b9776c 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -603,6 +603,7 @@
    - insecure-fork-wanted
    - insecure-setuid-wanted
    - issuers-chain-path
+   - localpeer
    - log
    - log-tag
    - log-send-hostname
@@ -969,6 +970,15 @@
   "issuers-chain-path" directory. All other certificates with the same issuer
   will share the chain in memory.
 
+localpeer <name>
+  Sets the local instance's peer name. It will be ignored if the "-L"
+  command line argument is specified or if used after "peers" section
+  definitions. In such cases, a warning message will be emitted during
+  the configuration parsing.
+
+  This option will also set the HAPROXY_LOCALPEER environment variable.
+  See also "-L" in the management guide and "peers" section below.
+
 log <address> [len <length>] [format <format>] [sample <ranges>:<smp_size>]
     <facility> [max level [min level]]
   Adds a global syslog server. Several global servers can be defined. They
@@ -2323,18 +2333,19 @@
 peer <peername> <ip>:<port> [param*]
   Defines a peer inside a peers section.
   If <peername> is set to the local peer name (by default hostname, or forced
-  using "-L" command line option), haproxy will listen for incoming remote peer
-  connection on <ip>:<port>. Otherwise, <ip>:<port> defines where to connect to
-  to join the remote peer, and <peername> is used at the protocol level to
-  identify and validate the remote peer on the server side.
+  using "-L" command line option or "localpeer" global configuration setting),
+  haproxy will listen for incoming remote peer connection on <ip>:<port>.
+  Otherwise, <ip>:<port> defines where to connect to in order to join the
+  remote peer, and <peername> is used at the protocol level to identify and
+  validate the remote peer on the server side.
 
   During a soft restart, local peer <ip>:<port> is used by the old instance to
   connect the new one and initiate a complete replication (teaching process).
 
   It is strongly recommended to have the exact same peers declaration on all
-  peers and to only rely on the "-L" command line argument to change the local
-  peer name. This makes it easier to maintain coherent configuration files
-  across all peers.
+  peers and to only rely on the "-L" command line argument or the "localpeer"
+  global configuration setting to change the local peer name. This makes it
+  easier to maintain coherent configuration files across all peers.
 
   You may want to reference some environment variables in the address
   parameter, see section 2.3 about environment variables.
diff --git a/include/haproxy/global-t.h b/include/haproxy/global-t.h
index 7db5412..f5bf216 100644
--- a/include/haproxy/global-t.h
+++ b/include/haproxy/global-t.h
@@ -127,6 +127,7 @@
 	char *chroot;
 	char *pidfile;
 	char *node, *desc;		/* node name & description */
+	int localpeer_cmdline;		/* whether or not the commandline "-L" was set */
 	struct buffer log_tag;           /* name for syslog */
 	struct list logsrvs;
 	char *log_send_hostname;   /* set hostname in syslog header */
diff --git a/src/cfgparse-global.c b/src/cfgparse-global.c
index a4fed04..ea47bbd 100644
--- a/src/cfgparse-global.c
+++ b/src/cfgparse-global.c
@@ -15,6 +15,7 @@
 #include <haproxy/compression.h>
 #include <haproxy/global.h>
 #include <haproxy/log.h>
+#include <haproxy/peers.h>
 #include <haproxy/tools.h>
 
 /*
@@ -1207,6 +1208,40 @@
 		else
 			global.tune.options |= GTUNE_STRICT_LIMITS;
 	}
+	else if (!strcmp(args[0], "localpeer")) {
+		if (alertif_too_many_args(1, file, linenum, args, &err_code))
+			goto out;
+
+		if (*(args[1]) == 0) {
+			ha_alert("parsing [%s:%d] : '%s' expects a name as an argument.\n",
+			         file, linenum, args[0]);
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+
+		if (global.localpeer_cmdline != 0) {
+			ha_warning("parsing [%s:%d] : '%s' ignored since it is already set by using the '-L' "
+			           "command line argument.\n", file, linenum, args[0]);
+			err_code |= ERR_WARN;
+			goto out;
+		}
+
+		if (cfg_peers) {
+			ha_warning("parsing [%s:%d] : '%s' ignored since it is used after 'peers' section.\n",
+			           file, linenum, args[0]);
+			err_code |= ERR_WARN;
+			goto out;
+		}
+
+		free(localpeer);
+		if ((localpeer = strdup(args[1])) == NULL) {
+			ha_alert("parsing [%s:%d]: cannot allocate memory for '%s'.\n",
+			         file, linenum, args[0]);
+			err_code |= ERR_ALERT | ERR_FATAL;
+			goto out;
+		}
+		setenv("HAPROXY_LOCALPEER", localpeer, 1);
+	}
 	else {
 		struct cfg_kw_list *kwl;
 		int index;
diff --git a/src/haproxy.c b/src/haproxy.c
index 1efa3ac..06e5a22 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1964,6 +1964,7 @@
 						exit(EXIT_FAILURE);
 					}
 					setenv("HAPROXY_LOCALPEER", localpeer, 1);
+					global.localpeer_cmdline = 1;
 					break;
 				case 'f' :
 					if (!list_append_word(&cfg_cfgfiles, *argv, &err_msg)) {