Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I have haproxy running as my load-balancer and from the stats web interface that comes with haproxy, I can put a web server into maintenance mode (and bring it back out again) - which is great!

However, I also want to be able to perform that same action from the command line (for use in some automated deployment workflows). Is this possible, and if so how?

Many thanks

share|improve this question

3 Answers 3

up vote 33 down vote accepted

Update (28 Aug 2012): I now tend to use haproxyctl nowadays, which utilizes the methods described below.

I've fixed it after a little more research, for anyone else with the same issue:-

You can add a unix socket in your config, then interact with that (here are the possible commands).

To set up:

sudo nano /etc/haproxy/haproxy.cfg

In your 'global' section add in:

stats socket /etc/haproxy/haproxysock level admin

Restart your haproxy daemon (e.g. sudo service haproxy restart)

Now you need socat (if you don't have it, just apt-get install socat on Ubuntu).

Now all you need to do is fire off this command to take down a node:

echo "disable server yourbackendname/yourservername" | socat stdio /etc/haproxy/haproxysock

To bring it back up replace disable with enable in the command above.

share|improve this answer

In addition to beardwizzle's echo method, you can also do this interactively:

root@ny-lb01:/etc/haproxy# sudo socat readline /var/run/haproxy.stat 

> set timeout cli 1d
> disable server foo/web01
> help
Unknown command. Please enter one of the following commands only :
  clear counters : clear max statistics counters (add 'all' for all counters)
  clear table    : remove an entry from a table
  help           : this message
  prompt         : toggle interactive mode with prompt
  quit           : disconnect
  show info      : report information about the running process
  show stat      : report counters for each proxy and server
  show errors    : report last request and response errors for each proxy
  show sess [id] : report the list of current sessions or dump this session
  show table [id]: report table usage stats or dump this table's contents
  get weight     : report a server's current weight
  set weight     : change a server's weight
  set timeout    : change a timeout setting
  disable server : set a server in maintenance mode
  enable server  : re-enable a server that was previously in maintenance mode
share|improve this answer

You can also temporarily "remove" the health check page from one server, to get the endpoint down and then publish your application.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.