Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a setup with one HAproxy server (frontend) and multiple web-servers (backend). Is it possible to configure HAproxy so that a script is executed when a web-server gets down?

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

I think what you're asking is you want to send a mail when one of the backend servers goes down, correct? I don't believe there's a way to trigger this from within HAProxy itself. One way to do this is to have a script check the status of the backends periodically and send an email if a backend is down. You can use the HAProxy socket interface to get this info. Docs are here. You'll probably need to parse the output from the show stat command. Good luck!

share|improve this answer
add comment

I believe below script will help you.Please modify it as per your need You need to schedule it in you cron. You can use mailx to send email when apache goes down and when it gets restarted.

RESTART="/etc/init.d/httpd restart"

#incase if you are on Deb based boxes
#RESTART="/etc/init.d/apache2 restart"


PGREP="/usr/bin/pgrep"

HTTPD="httpd"

# find httpd pid
$PGREP ${HTTPD}

if [ $? -ne 0 ] 
then
 # restart apache
 $RESTART
fi
share|improve this answer
add comment

You can do this via HaProxy itself ,it provides you httpchk directive below are some example Syntax

option httpchk
option httpchk <uri>
option httpchk <method> <uri>
option httpchk <method> <uri> <version>
share|improve this answer
    
With httpchk I can only specify how to check if server is down and I need a event /callback function that is executed when server gets down. –  Mike Owen Feb 12 '13 at 19:22
    
What do you mean by event/callback function and what you want to do when your web server goes down? You mean to say you want to bring up your web server again in case if your IIS/apache get crashed? –  Abhishek Anand Amralkar Feb 13 '13 at 3:21
    
I need to send an email to myself when a webserver node goes down, so basically I need execute a bash script when that happens. –  Mike Owen Feb 13 '13 at 9:16
    
I believe below script will help you –  Abhishek Anand Amralkar Feb 13 '13 at 9:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.