blob: cc120d855daeb0c89b2b5abb75f4060841a5b058 [file] [log] [blame]
willy tarreau982249e2005-12-18 00:57:06 +01001#!/bin/sh
2#
3# chkconfig: - 85 15
Willy Tarreau58000fe2021-05-09 06:25:16 +02004# description: HAProxy is a TCP/HTTP reverse proxy which is particularly suited \
willy tarreau982249e2005-12-18 00:57:06 +01005# 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
Adam Spiers85bb5ca2015-02-23 15:28:37 +000035BIN=/usr/sbin/$BASENAME
36
Adam Spiers5e71b6f2015-02-23 15:28:36 +000037CFG=/etc/$BASENAME/$BASENAME.cfg
38[ -f $CFG ] || exit 1
willy tarreau982249e2005-12-18 00:57:06 +010039
Adam Spiers922a37b2015-02-23 15:28:38 +000040PIDFILE=/var/run/$BASENAME.pid
Adam Spiersc5123f32015-02-23 15:28:39 +000041LOCKFILE=/var/lock/subsys/$BASENAME
Adam Spiers922a37b2015-02-23 15:28:38 +000042
willy tarreau982249e2005-12-18 00:57:06 +010043RETVAL=0
44
45start() {
Adam Spiersecb74a32015-02-23 15:28:40 +000046 quiet_check
willy tarreau982249e2005-12-18 00:57:06 +010047 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 Spiers922a37b2015-02-23 15:28:38 +000053 daemon $BIN -D -f $CFG -p $PIDFILE
willy tarreau982249e2005-12-18 00:57:06 +010054 RETVAL=$?
55 echo
Adam Spiersc5123f32015-02-23 15:28:39 +000056 [ $RETVAL -eq 0 ] && touch $LOCKFILE
willy tarreau982249e2005-12-18 00:57:06 +010057 return $RETVAL
58}
59
60stop() {
61 echo -n "Shutting down $BASENAME: "
62 killproc $BASENAME -USR1
63 RETVAL=$?
64 echo
Adam Spiersc5123f32015-02-23 15:28:39 +000065 [ $RETVAL -eq 0 ] && rm -f $LOCKFILE
Adam Spiers922a37b2015-02-23 15:28:38 +000066 [ $RETVAL -eq 0 ] && rm -f $PIDFILE
willy tarreau982249e2005-12-18 00:57:06 +010067 return $RETVAL
68}
69
70restart() {
Adam Spiersecb74a32015-02-23 15:28:40 +000071 quiet_check
willy tarreau982249e2005-12-18 00:57:06 +010072 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 Tarreau3909a2a2009-05-01 15:49:56 +020080reload() {
Adam Spiers107ddc12015-02-23 15:28:41 +000081 if ! [ -s $PIDFILE ]; then
82 return 0
83 fi
84
Adam Spiersecb74a32015-02-23 15:28:40 +000085 quiet_check
Willy Tarreau3909a2a2009-05-01 15:49:56 +020086 if [ $? -ne 0 ]; then
87 echo "Errors found in configuration file, check it with '$BASENAME check'."
88 return 1
89 fi
Adam Spiers922a37b2015-02-23 15:28:38 +000090 $BIN -D -f $CFG -p $PIDFILE -sf $(cat $PIDFILE)
Willy Tarreau3909a2a2009-05-01 15:49:56 +020091}
92
willy tarreau982249e2005-12-18 00:57:06 +010093check() {
Adam Spiers85bb5ca2015-02-23 15:28:37 +000094 $BIN -c -q -V -f $CFG
willy tarreau982249e2005-12-18 00:57:06 +010095}
96
jesse.defer@asu.educ04b16c2015-10-31 20:29:56 -070097quiet_check() {
Adam Spiersecb74a32015-02-23 15:28:40 +000098 $BIN -c -q -f $CFG
99}
100
willy tarreau982249e2005-12-18 00:57:06 +0100101rhstatus() {
102 status $BASENAME
103}
104
105condrestart() {
Adam Spiersc5123f32015-02-23 15:28:39 +0000106 [ -e $LOCKFILE ] && restart || :
willy tarreau982249e2005-12-18 00:57:06 +0100107}
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)
Willy Tarreau3909a2a2009-05-01 15:49:56 +0200121 reload
willy tarreau982249e2005-12-18 00:57:06 +0100122 ;;
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 Tarreau98edd772007-12-02 14:02:52 +0100134 exit 1
willy tarreau982249e2005-12-18 00:57:06 +0100135esac
136
Willy Tarreau98edd772007-12-02 14:02:52 +0100137exit $?