Configuration basics
Programs
Deprecation notice
The program feature is marked deprecated in:
- HAProxy 3.1 and newer
- HAProxy Enterprise 3.1 and newer
- HAProxy ALOHA 17.0 and newer
The program feature will be removed in HAProxy 3.3. Until that time, the program section will behave differently. During a reload of HAProxy, the master load balancer process will start a configured program, but a worker process will execute the rest of the program instead. A program can execute even if the worker process has a faulty configuration at reload.
To replace the program feature, we suggest using process managers such as Systemd, SysVinit, Supervisord, or Docker s6-overlays.
Available since
- HAProxy 2.0
- HAProxy Enterprise 2.0r1
- HAProxy ALOHA 11.5
Add the program section to specify an external program that should run as a child process under the load balancer process.
Configure an external program Jump to heading
A program section in your configuration contains a set of directives that define the program to be run, its command-line options and flags, as well as user, group, and restart options.
Below, we run the echo command to print Hello World! to standard out when the load balancer starts. Note that this requires you to enable master-worker mode.
haproxyglobalmaster-workerprogram echocommand echo "Hello, World!"
haproxyglobalmaster-workerprogram echocommand echo "Hello, World!"
Here’s a functionally equivalent example that sets the user and group directives:
haproxyprogram echocommand echo "Hello, World!"user hapee-lbgroup hapee
haproxyprogram echocommand echo "Hello, World!"user hapee-lbgroup hapee
When you restart the load balancer, you can see that the echo command execute then exit without error. You can use the program section to execute long-running programs that live alongside the load balancer too. Programs will restart and reload when the load balancer does, unless you specify no option start-on-reload.
After restarting the service, the echo program’s output displays:
outputtext[NOTICE] 324/184322 (3330) : New program 'echo' (3351) forked[NOTICE] 324/184322 (3330) : New worker #1 (3352) forkedsystemd[1]: Started Load Balancer.Hello, World![ALERT] 324/184322 (3330) : Current program 'echo' (3351) exited with code 0 (Exit)
outputtext[NOTICE] 324/184322 (3330) : New program 'echo' (3351) forked[NOTICE] 324/184322 (3330) : New worker #1 (3352) forkedsystemd[1]: Started Load Balancer.Hello, World![ALERT] 324/184322 (3330) : Current program 'echo' (3351) exited with code 0 (Exit)
Example Jump to heading
A common way to use this feature is to start long-running programs that augment the load balancer functionality; therefore, it makes sense to tie them to the lifetime of the load balancer’s process. For example, you can start Stream Processing Offload Agent programs such as the Traffic Mirror agent:
haproxyglobalmaster-workerprogram mirrorcommand spoa-mirror --runtime 0 --mirror-url http://test.local
haproxyglobalmaster-workerprogram mirrorcommand spoa-mirror --runtime 0 --mirror-url http://test.local
Note that all flags that follow the program’s name are passed directly to the program.
Add a user and group Jump to heading
You can also specify a user and group to use when executing the command:
haproxyglobalmaster-workerprogram mirrorcommand spoa-mirror --runtime 0 --mirror-url http://test.localuser ocagroup users
haproxyglobalmaster-workerprogram mirrorcommand spoa-mirror --runtime 0 --mirror-url http://test.localuser ocagroup users
Disable program restarts Jump to heading
By default, the load balancer stops and recreates child programs at reload. To disable this, add the no option start-on-reload directive to a program section:
haproxyglobalmaster-workerprogram mirrorcommand spoa-mirror --runtime 0 --mirror-url http://test.localuser ocagroup usersno option start-on-reload
haproxyglobalmaster-workerprogram mirrorcommand spoa-mirror --runtime 0 --mirror-url http://test.localuser ocagroup usersno option start-on-reload
See also Jump to heading
- For complete details on the program section, see the Programs reference.
Do you have any suggestions on how we can improve the content of this page?