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 | |
Willy Tarreau | 3909a2a | 2009-05-01 15:49:56 +0200 | [diff] [blame] | 74 | reload() { |
| 75 | /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg |
| 76 | if [ $? -ne 0 ]; then |
| 77 | echo "Errors found in configuration file, check it with '$BASENAME check'." |
| 78 | return 1 |
| 79 | fi |
| 80 | /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid) |
| 81 | } |
| 82 | |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 83 | check() { |
| 84 | /usr/sbin/$BASENAME -c -q -V -f /etc/$BASENAME/$BASENAME.cfg |
| 85 | } |
| 86 | |
| 87 | rhstatus() { |
| 88 | status $BASENAME |
| 89 | } |
| 90 | |
| 91 | condrestart() { |
| 92 | [ -e /var/lock/subsys/$BASENAME ] && restart || : |
| 93 | } |
| 94 | |
| 95 | # See how we were called. |
| 96 | case "$1" in |
| 97 | start) |
| 98 | start |
| 99 | ;; |
| 100 | stop) |
| 101 | stop |
| 102 | ;; |
| 103 | restart) |
| 104 | restart |
| 105 | ;; |
| 106 | reload) |
Willy Tarreau | 3909a2a | 2009-05-01 15:49:56 +0200 | [diff] [blame] | 107 | reload |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 108 | ;; |
| 109 | condrestart) |
| 110 | condrestart |
| 111 | ;; |
| 112 | status) |
| 113 | rhstatus |
| 114 | ;; |
| 115 | check) |
| 116 | check |
| 117 | ;; |
| 118 | *) |
| 119 | echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}" |
Willy Tarreau | 98edd77 | 2007-12-02 14:02:52 +0100 | [diff] [blame] | 120 | exit 1 |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 121 | esac |
| 122 | |
Willy Tarreau | 98edd77 | 2007-12-02 14:02:52 +0100 | [diff] [blame] | 123 | exit $? |