Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 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
HA-Proxy version 1.6 introduced that functionality natively with the Mailer Directive. – HBruijn Sep 9 '15 at 11:38

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"



# find httpd pid

if [ $? -ne 0 ] 
 # restart apache
share|improve this answer

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

Your Answer


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.