willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # chkconfig: - 85 15 |
| 4 | # description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \ |
| 5 | # for high availability environments. |
| 6 | # processname: haproxy |
| 7 | # config: /etc/haproxy/haproxy.cfg |
| 8 | # pidfile: /var/run/haproxy.pid |
| 9 | |
| 10 | # Script Author: Simon Matter <simon.matter@invoca.ch> |
| 11 | # Version: 2004060600 |
| 12 | |
| 13 | # Source function library. |
| 14 | if [ -f /etc/init.d/functions ]; then |
| 15 | . /etc/init.d/functions |
| 16 | elif [ -f /etc/rc.d/init.d/functions ] ; then |
| 17 | . /etc/rc.d/init.d/functions |
| 18 | else |
| 19 | exit 0 |
| 20 | fi |
| 21 | |
| 22 | # Source networking configuration. |
| 23 | . /etc/sysconfig/network |
| 24 | |
| 25 | # Check that networking is up. |
| 26 | [ ${NETWORKING} = "no" ] && exit 0 |
| 27 | |
| 28 | # This is our service name |
| 29 | BASENAME=`basename $0` |
| 30 | if [ -L $0 ]; then |
| 31 | BASENAME=`find $0 -name $BASENAME -printf %l` |
| 32 | BASENAME=`basename $BASENAME` |
| 33 | fi |
| 34 | |
| 35 | [ -f /etc/$BASENAME/$BASENAME.cfg ] || exit 1 |
| 36 | |
| 37 | RETVAL=0 |
| 38 | |
| 39 | start() { |
| 40 | /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg |
| 41 | if [ $? -ne 0 ]; then |
| 42 | echo "Errors found in configuration file, check it with '$BASENAME check'." |
| 43 | return 1 |
| 44 | fi |
| 45 | |
| 46 | echo -n "Starting $BASENAME: " |
| 47 | daemon /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid |
| 48 | RETVAL=$? |
| 49 | echo |
| 50 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME |
| 51 | return $RETVAL |
| 52 | } |
| 53 | |
| 54 | stop() { |
| 55 | echo -n "Shutting down $BASENAME: " |
| 56 | killproc $BASENAME -USR1 |
| 57 | RETVAL=$? |
| 58 | echo |
| 59 | [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME |
| 60 | [ $RETVAL -eq 0 ] && rm -f /var/run/$BASENAME.pid |
| 61 | return $RETVAL |
| 62 | } |
| 63 | |
| 64 | restart() { |
| 65 | /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg |
| 66 | if [ $? -ne 0 ]; then |
| 67 | echo "Errors found in configuration file, check it with '$BASENAME check'." |
| 68 | return 1 |
| 69 | fi |
| 70 | stop |
| 71 | start |
| 72 | } |
| 73 | |
| 74 | check() { |
| 75 | /usr/sbin/$BASENAME -c -q -V -f /etc/$BASENAME/$BASENAME.cfg |
| 76 | } |
| 77 | |
| 78 | rhstatus() { |
| 79 | status $BASENAME |
| 80 | } |
| 81 | |
| 82 | condrestart() { |
| 83 | [ -e /var/lock/subsys/$BASENAME ] && restart || : |
| 84 | } |
| 85 | |
| 86 | # See how we were called. |
| 87 | case "$1" in |
| 88 | start) |
| 89 | start |
| 90 | ;; |
| 91 | stop) |
| 92 | stop |
| 93 | ;; |
| 94 | restart) |
| 95 | restart |
| 96 | ;; |
| 97 | reload) |
| 98 | restart |
| 99 | ;; |
| 100 | condrestart) |
| 101 | condrestart |
| 102 | ;; |
| 103 | status) |
| 104 | rhstatus |
| 105 | ;; |
| 106 | check) |
| 107 | check |
| 108 | ;; |
| 109 | *) |
| 110 | echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}" |
| 111 | RETVAL=1 |
| 112 | esac |
| 113 | |
| 114 | exit $RETVAL |