willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # chkconfig: - 85 15 |
Willy Tarreau | 58000fe | 2021-05-09 06:25:16 +0200 | [diff] [blame] | 4 | # description: HAProxy is a TCP/HTTP reverse proxy which is particularly suited \ |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 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 | |
Adam Spiers | 85bb5ca | 2015-02-23 15:28:37 +0000 | [diff] [blame] | 35 | BIN=/usr/sbin/$BASENAME |
| 36 | |
Adam Spiers | 5e71b6f | 2015-02-23 15:28:36 +0000 | [diff] [blame] | 37 | CFG=/etc/$BASENAME/$BASENAME.cfg |
| 38 | [ -f $CFG ] || exit 1 |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 39 | |
Adam Spiers | 922a37b | 2015-02-23 15:28:38 +0000 | [diff] [blame] | 40 | PIDFILE=/var/run/$BASENAME.pid |
Adam Spiers | c5123f3 | 2015-02-23 15:28:39 +0000 | [diff] [blame] | 41 | LOCKFILE=/var/lock/subsys/$BASENAME |
Adam Spiers | 922a37b | 2015-02-23 15:28:38 +0000 | [diff] [blame] | 42 | |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 43 | RETVAL=0 |
| 44 | |
| 45 | start() { |
Adam Spiers | ecb74a3 | 2015-02-23 15:28:40 +0000 | [diff] [blame] | 46 | quiet_check |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 47 | if [ $? -ne 0 ]; then |
| 48 | echo "Errors found in configuration file, check it with '$BASENAME check'." |
| 49 | return 1 |
| 50 | fi |
| 51 | |
| 52 | echo -n "Starting $BASENAME: " |
Adam Spiers | 922a37b | 2015-02-23 15:28:38 +0000 | [diff] [blame] | 53 | daemon $BIN -D -f $CFG -p $PIDFILE |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 54 | RETVAL=$? |
| 55 | echo |
Adam Spiers | c5123f3 | 2015-02-23 15:28:39 +0000 | [diff] [blame] | 56 | [ $RETVAL -eq 0 ] && touch $LOCKFILE |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 57 | return $RETVAL |
| 58 | } |
| 59 | |
| 60 | stop() { |
| 61 | echo -n "Shutting down $BASENAME: " |
| 62 | killproc $BASENAME -USR1 |
| 63 | RETVAL=$? |
| 64 | echo |
Adam Spiers | c5123f3 | 2015-02-23 15:28:39 +0000 | [diff] [blame] | 65 | [ $RETVAL -eq 0 ] && rm -f $LOCKFILE |
Adam Spiers | 922a37b | 2015-02-23 15:28:38 +0000 | [diff] [blame] | 66 | [ $RETVAL -eq 0 ] && rm -f $PIDFILE |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 67 | return $RETVAL |
| 68 | } |
| 69 | |
| 70 | restart() { |
Adam Spiers | ecb74a3 | 2015-02-23 15:28:40 +0000 | [diff] [blame] | 71 | quiet_check |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 72 | if [ $? -ne 0 ]; then |
| 73 | echo "Errors found in configuration file, check it with '$BASENAME check'." |
| 74 | return 1 |
| 75 | fi |
| 76 | stop |
| 77 | start |
| 78 | } |
| 79 | |
Willy Tarreau | 3909a2a | 2009-05-01 15:49:56 +0200 | [diff] [blame] | 80 | reload() { |
Adam Spiers | 107ddc1 | 2015-02-23 15:28:41 +0000 | [diff] [blame] | 81 | if ! [ -s $PIDFILE ]; then |
| 82 | return 0 |
| 83 | fi |
| 84 | |
Adam Spiers | ecb74a3 | 2015-02-23 15:28:40 +0000 | [diff] [blame] | 85 | quiet_check |
Willy Tarreau | 3909a2a | 2009-05-01 15:49:56 +0200 | [diff] [blame] | 86 | if [ $? -ne 0 ]; then |
| 87 | echo "Errors found in configuration file, check it with '$BASENAME check'." |
| 88 | return 1 |
| 89 | fi |
Adam Spiers | 922a37b | 2015-02-23 15:28:38 +0000 | [diff] [blame] | 90 | $BIN -D -f $CFG -p $PIDFILE -sf $(cat $PIDFILE) |
Willy Tarreau | 3909a2a | 2009-05-01 15:49:56 +0200 | [diff] [blame] | 91 | } |
| 92 | |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 93 | check() { |
Adam Spiers | 85bb5ca | 2015-02-23 15:28:37 +0000 | [diff] [blame] | 94 | $BIN -c -q -V -f $CFG |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 95 | } |
| 96 | |
jesse.defer@asu.edu | c04b16c | 2015-10-31 20:29:56 -0700 | [diff] [blame] | 97 | quiet_check() { |
Adam Spiers | ecb74a3 | 2015-02-23 15:28:40 +0000 | [diff] [blame] | 98 | $BIN -c -q -f $CFG |
| 99 | } |
| 100 | |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 101 | rhstatus() { |
| 102 | status $BASENAME |
| 103 | } |
| 104 | |
| 105 | condrestart() { |
Adam Spiers | c5123f3 | 2015-02-23 15:28:39 +0000 | [diff] [blame] | 106 | [ -e $LOCKFILE ] && restart || : |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | # See how we were called. |
| 110 | case "$1" in |
| 111 | start) |
| 112 | start |
| 113 | ;; |
| 114 | stop) |
| 115 | stop |
| 116 | ;; |
| 117 | restart) |
| 118 | restart |
| 119 | ;; |
| 120 | reload) |
Willy Tarreau | 3909a2a | 2009-05-01 15:49:56 +0200 | [diff] [blame] | 121 | reload |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 122 | ;; |
| 123 | condrestart) |
| 124 | condrestart |
| 125 | ;; |
| 126 | status) |
| 127 | rhstatus |
| 128 | ;; |
| 129 | check) |
| 130 | check |
| 131 | ;; |
| 132 | *) |
| 133 | echo $"Usage: $BASENAME {start|stop|restart|reload|condrestart|status|check}" |
Willy Tarreau | 98edd77 | 2007-12-02 14:02:52 +0100 | [diff] [blame] | 134 | exit 1 |
willy tarreau | 982249e | 2005-12-18 00:57:06 +0100 | [diff] [blame] | 135 | esac |
| 136 | |
Willy Tarreau | 98edd77 | 2007-12-02 14:02:52 +0100 | [diff] [blame] | 137 | exit $? |