@@ -935,7 +935,77 @@ existing variables, not empty ones.
935935 user "$HAPROXY_USER"
936936
937937Some variables are defined by HAProxy, they can be used in the configuration
938- file, or could be inherited by a program (See 3.7. Programs):
938+ file, or could be inherited by a program (See 3.7. Programs). These variables
939+ are listed in the matrix below, and they are classified among four categories:
940+
941+ * usable: the variable is accessible from the configuration, either to be
942+ resolved as-is, or used within conditional blocks or predicates to enable
943+ or disable this some configuration fragments, as described in section 2.4
944+ "Conditional blocks".
945+
946+ * modifiable: the variable can be redefined or unset in the configuration via
947+ "setenv"/"unsetenv" keywords.
948+
949+ * listed: the variable is listed in CLI's "show env" command output,
950+ described in section 9.3 "Unix Sockets commands" of the management guide.
951+
952+ * exported: variable is exported to launch programs in a modified environment
953+ (See section 3.7 "Programs"). Note that this does not apply to external
954+ checks which have their own rules regarding exported variables.
955+
956+ There also two subcategories "master" and "worker", respectively marked 'M' and
957+ 'W' in the table below, showing the differences between the two processes when
958+ HAProxy is launched in master-worker mode.
959+
960+ * master: the variable is set and accessible from the master process. So, it
961+ will appear in the master CLI's "show env" output and it can be used in
962+ conditional blocks or directives to enable some special settings for the
963+ master (see examples in section 2.4 "Conditional blocks").
964+
965+ * worker: the variable is set and accessible from the worker process. It will
966+ appear in the worker CLI's "show env" (or the master CLI's "@1 show env")
967+ and it may as well condition some worker process parameters (see examples
968+ from section 2.4 "Conditional blocks").
969+
970+ In standalone mode (without "-W" option nor the "master-worker" keyword) the
971+ process behaves like a worker, except for variables "HAPROXY_MASTER_CLI" and
972+ "HAPROXY_MWORKER" which are not defined.
973+
974+ Some variables are marked as not usable and not modifiable:
975+
976+ * HAPROXY_CFGFILES
977+ * HAPROXY_MWORKER
978+ * HAPROXY_CLI
979+ * HAPROXY_MASTER_CLI
980+ * HAPROXY_LOCALPEER
981+
982+ Their values are undefined during configuration parsing, they are set later
983+ during the initialization. So, it's recommended not to use these variables
984+ within conditional blocks and not to reference them in the global section's
985+ "setenv"/"resetenv"/"unsetenv" keywords.
986+
987+ The table below summaries the status of each variable for the different working
988+ modes:
989+
990+ +--------------------------+----------+---------+------------+-----------+
991+ | variable | exported | usable | modifiable | listed |
992+ | | +---------+------------+-----------+
993+ | | | M | W | M | W | M | W |
994+ +--------------------------+----------+----+----+------+-----+-----+-----+
995+ | HAPROXY_STARTUP_VERSION | X | X | X | | | X | X |
996+ | HAPROXY_BRANCH | X | X | X | | | X | X |
997+ | HAPROXY_CFGFILES | X | | | | | X | X |
998+ | HAPROXY_MWORKER | X | | | | | X | X |
999+ | HAPROXY_CLI | | | | | | | X |
1000+ | HAPROXY_MASTER_CLI | | | | | | X | |
1001+ | HAPROXY_LOCALPEER | | | | | | | X |
1002+ | HAPROXY_HTTP_LOG_FMT | | | X | | X | | |
1003+ | HAPROXY_HTTP_CLF_LOG_FMT | | | X | | X | | |
1004+ | HAPROXY_HTTPS_LOG_FMT | | | X | | X | | |
1005+ | HAPROXY_TCP_LOG_FMT | | | X | | X | | |
1006+ +--------------------------+----------+----+----+------+-----+-----+-----+
1007+
1008+ The variables in question are the following:
9391009
9401010* HAPROXY_LOCALPEER: defined at the startup of the process which contains the
9411011 name of the local peer. (See "-L" in the management guide.)
@@ -968,8 +1038,8 @@ file, or could be inherited by a program (See 3.7. Programs):
9681038
9691039* HAPROXY_MWORKER: In master-worker mode, this variable is set to 1.
9701040
971- * HAPROXY_CLI: configured listeners addresses of the stats socket for every
972- processes, separated by semicolons.
1041+ * HAPROXY_CLI: configured listeners addresses of the stats socket of every
1042+ processe, these addresses are separated by semicolons.
9731043
9741044* HAPROXY_MASTER_CLI: In master-worker mode, listeners addresses of the master
9751045 CLI, separated by semicolons.
@@ -1006,8 +1076,6 @@ This way it is possible to emit information to help locate a rule in variables,
10061076logs, error statuses, health checks, header values, or even to use line numbers
10071077to name some config objects like servers for example.
10081078
1009- See also "external-check command" for other variables.
1010-
10111079
101210802.4. Conditional blocks
10131081-----------------------
@@ -1139,12 +1207,41 @@ The list of currently supported predicates is the following:
11391207
11401208Example:
11411209
1210+ # 1. HAPROXY_MWORKER variable is set automatically by HAProxy in master and
1211+ # in worker process environments (see HAProxy variables matrix from
1212+ # 2.3. Environment variables). Its presence enables an additional listener.
1213+
1214+ global
1215+ master-worker
1216+
11421217 .if defined(HAPROXY_MWORKER)
11431218 listen mwcli_px
11441219 bind :1111
11451220 ...
11461221 .endif
11471222
1223+ # 2. HAPROXY_BRANCH is set automatically by HAProxy in master and in worker
1224+ # process environments (see HAProxy variables matrix from 2.3. Environment
1225+ # variables). We check HAPROXY_BRANCH value and conditionally enable
1226+ # mworker-max-reloads parameter.
1227+
1228+ global
1229+ master-worker
1230+
1231+ .if streq("$HAPROXY_BRANCH",3.1)
1232+ mworker-max-reloads 5
1233+ .endif
1234+
1235+ # 3. Some arbitrary environment variables are set by user in the global
1236+ # section. If HAProxy is started in master-worker mode, they are presented in
1237+ # master and in worker process environments. We check values of these
1238+ # variables and conditionally enable ports 80 and 443. Environment variables
1239+ # checks can be mixed with features and version checks.
1240+
1241+ global
1242+ setenv WITH_SSL yes
1243+ unsetenv SSL_ONLY
1244+
11481245 .if strneq("$SSL_ONLY",yes)
11491246 bind :80
11501247 .endif
@@ -11291,8 +11388,6 @@ external-check command <command>
1129111388 PATH The PATH environment variable used when executing
1129211389 the command may be set using "external-check path".
1129311390
11294- See also "2.3. Environment variables" for other variables.
11295-
1129611391 If the command executed and exits with a zero status then the check is
1129711392 considered to have passed, otherwise the check is considered to have
1129811393 failed.
0 commit comments