Mascote

notes to self.

Controlling HAProxy With Socat for Fun and Profit

One nice thing to do when hacking some deploy/provision tools is the hability to provide rolling restart of backend servers without affecting existing traffic.

Ensure you have the stats socket enabled on your haproxy.cfg.

1
# echo "disable server www-backend/web12" | socat /run/haproxy/admin.sock stdio

Your server web12 from backend server group www-backend will enter on the maintenance mode, you can see with:

1
2
3
4
5
# echo "show stat" | socat /run/haproxy/admin.sock stdio
...
www-http,FRONTEND,,,0,6,2000,18,17584,39934,0,0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,4,,,,0,5,8,2,4,0,,0,4,19,,,0,0,0,0,,,,,,,,
www-backend,web12,0,0,0,1,,15,13936,39082,,0,,0,0,0,0,MAINT,1,1,0,,,,,,1,3,1,,15,,2,0,,4,,,,0,5,8,2,0,0,0,,,,0,0,,,,,865,,,0,0,0,17,
                                                      ^^^^^

Deploy and enable you backend again:

1
# echo "enable server www-backend/web12" | socat /run/haproxy/admin.sock stdio

You can mix as a before task with capistrano or a pre_tasks with ansible.