Hi Michele,
Le 02/03/2012 17:26, Michele Mazzucco a écrit :
Hello,
I am trying to enable/disable servers at runtime by means of the UNIX socket
created by HAProxy.
In order to do that, I am using the Python script below.
I'm testing the code with 2 servers, and I have noticed that quite often only
one of the 2 servers is enabled/disable (sometimes the first, others the
second). However sometimes none of them changes state, of both of them do.
I have tried to open the socket in non-interactive mode as well (i.e., re-open
the socket at every command), but I didn't notice any difference.
Am I doing anything wrong?, servers' names are something like i-a3c832c7.
As a side not, I should add that replacing the send() on the socket with socat
Maybe you didn't set your socket in "admin" level ?
global
stats socket ... level admin
echo disable server www/i-9bb943ff | socat stdio unix-connect:/tmp/haproxy
does not change the behavior of the system.
Thanks,
Michele
def change_state(self, servers_list, enable=True):
try:
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect(self.socket_path)
# interactive mode (see documentation, sec. 9.2)
s.send('prompt\n')
self.wait(s) # waits for the prompt
for i in servers_list:
command = None
if enable == True:
command = 'enable server www/%s' % i
else:
command = 'disable server www/%s' % i
log.info(command)
s.send('%s\n' % command)
self.wait(s)
s.shutdown(socket.SHUT_RDWR)
s.close()
except SocketError, e:
log.error('socket error: %s' % e)
self.__go = False
--
Cyril Bonté