aboutsummaryrefslogtreecommitdiff
path: root/network/haproxy/rc.haproxy
blob: e19ddf8ca5295ce545fedd4c61e5f5d260dccbb8 (plain)
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
#!/bin/bash
#
# Slackware initialization script for HAProxy.
#
# This script was made by T3slider.
# Slight modifications by Badchay.
#


HAPROXY=/usr/sbin/haproxy
CONFIG=/etc/haproxy/haproxy.cfg
PIDFILE=/var/run/haproxy.pid

if [[ ! -f $CONFIG && "$1" == "start" ]]; then
   echo "No configuration file found. Cannot continue."
   echo "The script looks for the configuration file placed in $CONFIG"
   exit 1
fi

start() {
    if [ -r $PIDFILE ]; then
        echo 'HAProxy is already running!'
        return
    else
    	echo "Starting HAProxy..."
        $HAPROXY -f $CONFIG -D -p $PIDFILE
    fi
}

stop() {
    if [ ! -r $PIDFILE ]; then
        echo 'HAProxy is not running!'
        return
    fi
    echo "Soft-stopping HAProxy..."
    kill -USR1 `cat $PIDFILE`
    # Even with the right permissions the PID file will not be removed...
    rm -f $PIDFILE
}

force_stop() {
    if [ ! -r $PIDFILE ]; then
        echo 'HAProxy is not running!'
        return
    fi
    echo "Hard-stopping HAProxy..."
    kill `cat $PIDFILE`
    # Even with the right permissions the PID file will not be removed...
    rm -f $PIDFILE
}

status() {
    if [ ! -r $PIDFILE ]; then
        echo "HAProxy is not running."
        return
    fi
    PID=`cat $PIDFILE`
    if [ -z "$PID" ]; then
        echo 'PID file is empty! HAProxy does not appear to be running, but there is a stale PID file.'
    elif kill -0 $PID; then
        echo "HAProxy is running."
    else
        echo "HAProxy is not running, but there is a stale PID file."
    fi
}

checkconfig() {
    $HAPROXY -c -q -V -f $CONFIG
}

case "$1" in
    'start')
        start
        ;;
    'stop')
        stop
        ;;
    'force_stop')
        force_stop
        ;;
    'restart')
        stop
        start
        ;;
    'force_restart')
        force_stop
        start
        ;;
    'status')
        status
        ;;
    'checkconfig')
        checkconfig
        ;;
    *)
        echo "Usage: $0 {start|stop|force_stop|restart|force_restart|status|checkconfig}"
        exit 1
        ;;
esac