From: Willy Tarreau Date: Tue, 15 Sep 2026 14:20:58 +0000 (+0200) Subject: MINOR: extcheck: pass the master and worker IDs to external checks X-Git-Tag: v3.5-dev7~6 X-Git-Url: https://git.kaiwu.me/?a=commitdiff_plain;h=a2e3bb6566398044d44ddba1f2bf768522dda481;p=haproxy.git MINOR: extcheck: pass the master and worker IDs to external checks By default, i.e. unless "external-check preserve-env" is used, the environment of an external check is not inherited but entirely rebuilt from the curated list in extcheck_envs[], so the two new identifiers would not be visible from a check script. Let's add them there, next to PATH, as a new process-scoped group before the proxy and server ones. It's also cleaner because we pass the real directives, not the env variables which could have been modified. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 1f3a096d4..3b44d7592 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -8123,6 +8123,13 @@ external-check command Some values are also provided through environment variables. Environment variables : + HAPROXY_MASTER_ID The unique identifier of the master process, or + empty when not running in master-worker mode. See + section 2.3. + + HAPROXY_WORKER_ID The unique identifier of the worker process. See + section 2.3 and the "worker-id" global keyword. + HAPROXY_PROXY_ADDR The first bind address if available (or empty if not applicable, for example in a "backend" section). diff --git a/src/extcheck.c b/src/extcheck.c index 3d325eaf8..e19c30afc 100644 --- a/src/extcheck.c +++ b/src/extcheck.c @@ -63,6 +63,10 @@ struct extcheck_env { enum { EXTCHK_PATH = 0, + /* Process specific environment variables */ + EXTCHK_HAPROXY_MASTER_ID, /* the master's unique ID (empty if no master) */ + EXTCHK_HAPROXY_WORKER_ID, /* the worker's unique ID */ + /* Proxy specific environment variables */ EXTCHK_HAPROXY_PROXY_NAME, /* the backend name */ EXTCHK_HAPROXY_PROXY_ID, /* the backend id */ @@ -84,6 +88,8 @@ enum { const struct extcheck_env extcheck_envs[EXTCHK_SIZE] = { [EXTCHK_PATH] = { "PATH", EXTCHK_SIZE_EVAL_INIT }, + [EXTCHK_HAPROXY_MASTER_ID] = { "HAPROXY_MASTER_ID", EXTCHK_SIZE_EVAL_INIT }, + [EXTCHK_HAPROXY_WORKER_ID] = { "HAPROXY_WORKER_ID", EXTCHK_SIZE_EVAL_INIT }, [EXTCHK_HAPROXY_PROXY_NAME] = { "HAPROXY_PROXY_NAME", EXTCHK_SIZE_EVAL_INIT }, [EXTCHK_HAPROXY_PROXY_ID] = { "HAPROXY_PROXY_ID", EXTCHK_SIZE_EVAL_INIT }, [EXTCHK_HAPROXY_PROXY_ADDR] = { "HAPROXY_PROXY_ADDR", EXTCHK_SIZE_EVAL_INIT }, @@ -331,6 +337,11 @@ int prepare_external_check(struct check *check) } EXTCHK_SETENV(check, EXTCHK_PATH, path, err); + /* Add process environment variables. The master's ID is empty when + * there is no master, i.e. when not running in master-worker mode. + */ + EXTCHK_SETENV(check, EXTCHK_HAPROXY_MASTER_ID, global.master_id ? global.master_id : "", err); + EXTCHK_SETENV(check, EXTCHK_HAPROXY_WORKER_ID, global.worker_id ? global.worker_id : "", err); /* Add proxy environment variables */ EXTCHK_SETENV(check, EXTCHK_HAPROXY_PROXY_NAME, px->id, err); EXTCHK_SETENV(check, EXTCHK_HAPROXY_PROXY_ID, ultoa_r(px->uuid, buf, sizeof(buf)), err);