Re: HAProxy Hot Reconfiguration with s6

From: Roger Pate <roger_at_qxxy.com>
Date: Thu, 19 May 2016 04:29:53 -0400

On Wed, May 18, 2016 at 11:32 PM, Colin Booth <cathexis_at_gmail.com> wrote:
> reload.sh:
> #!/bin/sh
> /usr/sbin/haproxy \
> -f /etc/haproxy/haproxy.cfg \
> -f /opt/haproxy-config/combined.cfg \
> -p /tmp/haproxy.pid \
> -sf $(sv s /opt/zsv/jboss/haproxy | awk '{print substr($4,1,length($4)-1)}')
>
> A couple of notes: the -sf option to haproxy is fine with taking a
> null option so you don't need to worry about having two exec lines. If
> you're in a startup or crash restart situation, ./run skips all the
> pid detection stuff and while $HANDOFFPID is empty, like I said it
> doesn't matter. If you're reloading, reload.sh starts a daemonized
> copy of haproxy (this is important, I'll explain in a sec) having dug
> out the process ID of the supervised copy from the output of sv status
> and saving the current pid in a well-known location so that when runsv
> restarts haproxy it's able to re-acquire all its fds.
>
> So, the special note about daemonization. if you run haproxy in
> foreground mode (-db), the -p flag does nothing. Since I need to get
> the process id for a clean hand-back, I can either scrape the pid via
> /proc or ps, or daemonize. Yes there's the standard pidfile race, but
> I figure the 1-2 second turnaround between termination of the
> supervised copy and the give-back is short-enough that it isn't too
> bad.

I don't know HAProxy, but if you want to run from reload.sh without
daemonizing, would this work?

reload.sh:
#!/bin/sh
echo $$ > /tmp/haproxy.pid
exec /usr/sbin/haproxy \
    -f /etc/haproxy/haproxy.cfg \
    -f /opt/haproxy-config/combined.cfg \
    -db \
    -sf $(sv s /opt/zsv/jboss/haproxy | awk '{print substr($4,1,length($4)-1)}')
Received on Thu May 19 2016 - 08:29:53 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:19 UTC