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.
14if [ -f /etc/init.d/functions ]; then
15  . /etc/init.d/functions
16elif [ -f /etc/rc.d/init.d/functions ] ; then
17  . /etc/rc.d/init.d/functions
18else
19  exit 0
20fi
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
29BASENAME=`basename $0`
30if [ -L $0 ]; then
31  BASENAME=`find $0 -name $BASENAME -printf %l`
32  BASENAME=`basename $BASENAME`
33fi
34
35BIN=/usr/sbin/$BASENAME
36
37CFG=/etc/$BASENAME/$BASENAME.cfg
38[ -f $CFG ] || exit 1
39
40PIDFILE=/var/run/$BASENAME.pid
41LOCKFILE=/var/lock/subsys/$BASENAME
42
43RETVAL=0
44
45start() {
46  quiet_check
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: "
53  daemon $BIN -D -f $CFG -p $PIDFILE
54  RETVAL=$?
55  echo
56  [ $RETVAL -eq 0 ] && touch $LOCKFILE
57  return $RETVAL
58}
59
60stop() {
61  echo -n "Shutting down $BASENAME: "
62  killproc $BASENAME -USR1
63  RETVAL=$?
64  echo
65  [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
66  [ $RETVAL -eq 0 ] && rm -f $PIDFILE
67  return $RETVAL
68}
69
70restart() {
71  quiet_check
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
80reload() {
81  if ! [ -s $PIDFILE ]; then
82    return 0
83  fi
84
85  quiet_check
86  if [ $? -ne 0 ]; then
87    echo "Errors found in configuration file, check it with '$BASENAME check'."
88    return 1
89  fi
90  $BIN -D -f $CFG -p $PIDFILE -sf $(cat $PIDFILE)
91}
92
93check() {
94  $BIN -c -q -V -f $CFG
95}
96
97quiet_check() {
98  $BIN -c -q -f $CFG
99}
100
101rhstatus() {
102  status $BASENAME
103}
104
105condrestart() {
106  [ -e $LOCKFILE ] && restart || :
107}
108
109# See how we were called.
110case "$1" in
111  start)
112    start
113    ;;
114  stop)
115    stop
116    ;;
117  restart)
118    restart
119    ;;
120  reload)
121    reload
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}"
134    exit 1
135esac
136
137exit $?
138