Reference
unpublish backend
Available since
- HAProxy 3.4
Make a dynamic backend unavailable for use.
Description Jump to heading
Marks the specified backend as unqualified for future traffic selection. Any use_backend or default_backend directives that reference it are ignored and the next content switching rules are evaluated. While in the unpublished state, server health checks are active. This command requires a CLI level of operator or admin.
You don’t have to remove servers from the backend before you unpublish it, but if you intend to delete the backend, you will have to delete the servers.
Examples Jump to heading
In this example, we make a backend unavailable for traffic. We have already removed servers by first putting them in maintenance mode using set server and then deleting them using del server.
nixecho "unpublish backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999
nixecho "unpublish backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999
Add a backend, server, and map file entry Jump to heading
In the following example, we add a backend, a server, and a map file entry that directs traffic to the new backend. Then we publish the backend so it becomes available for use in the load balancer. For a tutorial on map files, see Map files.
Before we make any changes, our example load balancer configuration starts off like this:
- In the global section, we enable the HAProxy Runtime API at port 9999.
- There’s a defaults section named
mydefaults. - There’s a frontend named
myfrontend1. - The
use_backenddirective reads a map file to determine the correct backend to use based on the requested URL path. The map file is virtual, meaning it exists in memory, and starts off empty. - If there isn’t a match in the map file for the requested URL path, the
default_backenddirective targets traffic to the backend namedwebservers.
Here’s the configuration file:
haproxyglobalstats socket ipv4@127.0.0.1:9999 level admindefaults mydefaultslog globalmode httpoption httplogoption dontlognulltimeout connect 10mtimeout client 10mtimeout server 10mfrontend myfrontend1bind :80use_backend %[path,map_beg(virt@paths.map)]default_backend webserversbackend webserversserver web1 127.0.0.1:8080
haproxyglobalstats socket ipv4@127.0.0.1:9999 level admindefaults mydefaultslog globalmode httpoption httplogoption dontlognulltimeout connect 10mtimeout client 10mtimeout server 10mfrontend myfrontend1bind :80use_backend %[path,map_beg(virt@paths.map)]default_backend webserversbackend webserversserver web1 127.0.0.1:8080
To add our dynamic backend and make the other changes, follow these steps:
-
Add a dynamic backend using the
add backendcommand. The backend is namedmybackend1and uses defaults from sectionmydefaults.nixecho "experimental-mode on; add backend mybackend1 from mydefaults" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "experimental-mode on; add backend mybackend1 from mydefaults" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Add a server using the
add servercommand.nixecho "add server mybackend1/web1 172.16.0.12:8080 check port 8080" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "add server mybackend1/web1 172.16.0.12:8080 check port 8080" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Enable the server using the
enable servercommand.nixecho "enable server mybackend1/web1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "enable server mybackend1/web1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Enable health checks for the server using the
enable healthcommand.nixecho "enable health mybackend1/web1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "enable health mybackend1/web1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Make the backend available for traffic using the
publish backendcommand.nixecho "publish backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "publish backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Add an entry to the map file.
nixecho "add map virt@paths.map /test mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "add map virt@paths.map /test mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999
The backend is available to accept traffic, and the map file has been updated with an entry that routes requests for the URL path /test to the new backend. Note that both the dynamic backend and the virtual map file reside only in memory in the running load balancer process. They do not exist in the configuration file on disk.
Delete backend, server, and map file entry Jump to heading
In the following example, we delete the server, backend, and map entry. Use these commands:
-
Put the server into maintenance mode. This command marks the server as “DOWN” for maintenance. The load balancer stops sending checks to this server while it’s in this state.
nixecho "set server mybackend1/web1 state maint" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "set server mybackend1/web1 state maint" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Wait for the server to be removable and then remove it. A server is removable when it no longer has any active or idle connections.
nixecho "wait 2s srv-removable mybackend1/web1; del server mybackend1/web1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "wait 2s srv-removable mybackend1/web1; del server mybackend1/web1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Unpublish the backend.
nixecho "unpublish backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "unpublish backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Wait for the backend to be removable and then delete it.
nixecho "experimental-mode on; wait 2s be-removable mybackend1; del backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "experimental-mode on; wait 2s be-removable mybackend1; del backend mybackend1" | \sudo socat stdio tcp4-connect:127.0.0.1:9999 -
Delete the map file entry.
nixecho "del map virt@paths.map /test" | \sudo socat stdio tcp4-connect:127.0.0.1:9999nixecho "del map virt@paths.map /test" | \sudo socat stdio tcp4-connect:127.0.0.1:9999
See also Jump to heading
- add backend
- del backend
- del map
- del server
- experimental mode
- publish backend
- set server
- wait
- To target a specific backend, see Use conditionals to forward traffic to different backends.
- To direct traffic to a backend even when disabled or unpublished, use the force-be-switch directive.