HAProxy – Set Backend Server in maintenance mode

First install socat

sudo apt update
sudo apt install socat -y

Execute the following command where <backend> and <Server> are replaced

echo "disable server <backend>/<Server>" | sudo socat unix-connect:/var/run/haproxy/admin.sock stdio

Example

echo "disable server back_kibana/logm-logstash-1" | sudo socat unix-connect:/var/run/haproxy/admin.sock stdio

We can verify the servers with socat with the following command

echo "show servers state" | sudo socat unix-connect:/var/run/haproxy/admin.sock stdio | grep logm-logstash-1

We get the following output

5 back_logstash 1 logm-logstash-1 172.16.16.16 0 1 1 1 1711 7 2 0 14 0 0 0 - 0 - 0 5044 - - 5044

We can see the srv_op_state has changed to the value 0, the srv_admin_state next to it has changed from 0 to 1. That combo is represented in the UI as “MAINT” status.