Hello Cyril,
no, those settings should be fine. Here is my configuration file.
global
stats socket /tmp/haproxy mode 666 level admin
stats timeout 1h
pidfile /var/run/haproxy.pid
daemon
spread-checks 5
defaults
log 127.0.0.1 local2 info
mode http
log global
option tcp-smart-accept
option tcp-smart-connect
retries 3
maxconn 10000
contimeout 4s
clitimeout 10s
srvtimeout 10s
timeout server 10s
frontend http-in
bind *:80
default_backend www
backend www
option httplog
stats enable
mode http
grace 5000
stats uri /admin?stats
stats refresh 5s
stats auth admin:admin
option forceclose
balance leastconn
option httpchk # sends an http request to monitor the servers
option redispatch
..... servers here
Michele
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é