~nchohan/appscale/zk3.3.4

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/sh
#
# /etc/rc.d/init.d/haproxy
# haproxy:This script starts and stops HAProxy 
#
# Author: Robert Simmons robert@me.com
#
# processname: haproxy
# chkconfig: 235 88 11
# description: HAProxy Load Balances network traffic according to its \
#       configuration
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid 
#
### BEGIN INIT INFO
# Provides: haproxy
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Should-Start: haproxy
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: Starts and Stops the HAProxy Load Balancer Process
# Description: Load Balances network traffic according to its configuration
### END INIT INFO

# Source function library.
#. /etc/init.d/functions
. /lib/lsb/init-functions

# BEGIN USER CONFIGURATION #
PROG="haproxy"
DIR=/usr/sbin
LBPATH=$DIR/haproxy
PIDFILE=/var/run/haproxy.pid
CONF=/etc/haproxy/haproxy.cfg
LOCKFILE=/var/lock/haproxy
OPTIONS="-D -f $CONF -p $PIDFILE"
# END USER CONFIGURATION #

RETVAL=0

start() {
    $LBPATH -c -q -f $CONF
    if [ $? -ne 0 ]; then
        echo "Errors in configuration, unable to start."
        exit 1
    fi

    echo -n "Starting $PROG: "
    if [ -f $PIDFILE ]; then
	PID=`cat $PIDFILE`
	echo -e "\nERROR - $PROG is already running: $PID"
	exit 1
    else
	$LBPATH $OPTIONS
	RETVAL=$?
	echo
	[ $RETVAL -eq 0 ] && touch ${LOCKFILE}
	return $RETVAL
    fi
}

stop() {
    echo -n "Stopping $PROG: "
    killproc $LBPATH -USR1
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
}
reload() {
    $LBPATH -c -q -f $CONF
    if [ $? -ne 0 ]; then
	echo "Errors in Configuration, unable to start."
	return 1
    fi
    echo -n $"Reloading $PROG...."
    $LBPATH $OPTIONS  -sf $(<${PIDFILE})
    RETVAL=$?
    echo " Finished."
}

check() {
    $LBPATH -c -q -f $CONF
}

case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    status)
	status haproxy
	;;
    reload)
	reload
	;;
    force-reload)
	restart
	;;
    restart)
	stop
	start
	;;
    *)
	echo "Usage: {start|stop|restart|reload|force-reload|status}"
	exit 1
	;;
esac
exit $?