Hello everyone,
I think I might have tracked down the problem.
According to the statistics I have retrieved by means of "show stat" after
enabling disabling servers, it looks like the socket is working as expected.
The might be in the web interface.
In my test, involving HAProxy 1.4.18 and 2 Apache servers being
enabled/disabled every 5 seconds, "show stat" was issued after every state
change (using a different socket) and reported the expected number of active
servers (i.e., either 0 or 2). On the other hand in a number of times the web
interface marked only 1 of the two serves in brown (MAINT).
Cheers,
Michele
It looks like servers are enabled/disabled
On Mar 2, 2012, at 7:25 PM, Cyril Bonté wrote:
> 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é