Restarting Haproxy Gracefully
As per various blogs, HAproxy can be gracefully restarted using the following command:
sudo haproxy -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid)
TO verify this, I had set up a apache bench script which contiguously sent message to haproxy. Ideally, whenever I restarted my server the script should not have an affect on the apache bunch execiton. But, it seems that whenever Haproxy is restarted apache bench scripts terminate and the connection to load balancer is lost.
Here is the details of my HaProxy configuration file :
global
nbproc 4
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
pidfile /var/run/haproxy.pid
stats socket /home/ubuntu/haproxy.sock
#debug
#quiet
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen webstats
bind 0.0.0.0:1000
stats enable
mode http
stats uri /lb?stats
stats auth anand:aaaaaaaa
#stats refresh
listen web-farm 0.0.0.0:80
mode http
balance roundrobin
option httpchk HEAD /index.php HTTP/1.0
server server2.com 1.1.1.1:80
server serve1.com 1.1.1.2:80
~
Please let me know what am I missing here.
Solution 1:
While troubleshooting this, try to use "nbproc 1" instead of "nbproc 4", increasing the number of processes is rarely needed, and could potentially lead to issues in certain cases.
However, this is most likely not the main problem. The scenario you describe should actually work as you expect.
HAProxy's hot reconfiguration actually works like this :
- A new process is started with the specified configuration
- The old process receives a SIGTTOU signal so that the new process can take over the port(s)
- The old process finishes it's current work and then exits
- The new process handles traffic over the port(s)
If anything goes wrong after 2, the old process instead receives a SIGTTIN signal, and continues as before.
Some additional detail in your question could make troubleshooting this problem easier:
- What parameters do you use with ab
- After a hot reconfiguration, can you connect to the new process with any other clients or not
- Which (major) version of HAProxy are you using