0

I am new to HA Proxy and Upstart Scripting. I am using, HA Proxy version 1.4.18 2011/09/16. I am trying to write an upstart script that will keep haproxy alive in case haproxy dies. This is what I have so far:

script
 if [ $(pgrep haproxy) ]; then
restart haproxy;
 else
start haproxy;
 fi
end script

Does look like a legible code?

quanta
  • 50,327
  • 19
  • 152
  • 213
Vladimir
  • 75
  • 1
  • 9

1 Answers1

3

use this code and put it in "/etc/init/haproxy.conf". The "respawn" line will take care of supervising the daemon and restart it if necessary.

description     "HAProxy"

start on runlevel [2345]
stop on runlevel [016]

respawn
respawn limit 2 5

env CONF=/etc/haproxy/haproxy.cfg

pre-start script
    [ -r $CONF ]
end script

exec /usr/local/sbin/haproxy -db -f $CONF
ofrommel
  • 221
  • 1
  • 4