I wasn't sure when I created this if it would be of interest to the
community, but please find attached my HAProxy Init script. It supports both
reloading and the "fancy green OK output" ;-).
Usage:
1. Update the user configuration section of the script with the path's to
your HAProxy binary and configuration file
2. Copy into /etc/init.d and name the file "haproxy" 3. Set the permissions to Executable ("chmod +x haproxy") 4. On a Redhat/Fedora system, configure it for use by running "chkconfig--add haproxy" and then to get it to start, "chkconfig haproxy on". 5. Then use "service haproxy start" to run HAProxy.
Hope this helps!
Robert.
-----Original Message-----
From: Willy Tarreau [mailto:w#1wt.eu]
Sent: 21 May 2009 05:33
To: Jeremy
Cc: haproxy#formilux.org
Subject: Re: reloading haproxy
On Wed, May 20, 2009 at 05:03:08PM -0500, Jeremy wrote:
> While we're on the subject, in case anyone else wants to use it (or
> knows a better way of doing this)... I stuck this in my haproxy init.d
> scrip (using CentOS/RedHat). I'm not sure how to make it do the fancy
> green [ OK ] output like start/stop does but that's ok.
I don't know for the colors, but I have comments below
> reload() {
> /usr/local/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg
here you use $BASENAME ...
> if [ $? -ne 0 ]; then
> echo "Errors found in configuration file, check it with '$BASENAME
> check'."
> return 1
> fi
> /usr/local/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -sf $(pidof
> haproxy)
...and here "haproxy".
> sleep 1
don't do that. If you add sleep, it will only make things work by pure luck and slow your system down for nothing.
> pidof haproxy > /var/run/$BASENAME.pid
better use -p /var/run/$BASENAME.pid like this :
/usr/local/sbin/haproxy -D -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid -sf $(cat /var/run/haproxy.pid 2>/dev/null)
That way haproxy sets the pid(s) file itself and checks that file, it does not rely on a tricky "pidof" call nor the presence of a "sleep" call.
Regards,
Willy
This archive was generated by hypermail 2.2.0 : 2009/05/21 13:00 CEST