~ubuntu-branches/ubuntu/intrepid/haproxy/intrepid

« back to all changes in this revision

Viewing changes to debian/haproxy.init

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Cornet
  • Date: 2008-03-09 21:30:29 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080309213029-8oupnrc607mg5uqw
Tags: 1.3.14.3-1
* New Upstream Version
* Add status argument support to init-script to conform to LSB.
* Cleanup pidfile after stop in init script. Init script return code fixups.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
PATH=/sbin:/usr/sbin:/bin:/usr/bin
15
15
PIDFILE=/var/run/haproxy.pid
 
16
CONFIG=/etc/haproxy/haproxy.cfg
16
17
HAPROXY=/usr/sbin/haproxy
17
 
CONFIG=/etc/haproxy.cfg
18
18
EXTRAOPTS=
19
19
ENABLED=0
20
20
 
41
41
 
42
42
haproxy_stop()
43
43
{
44
 
        start-stop-daemon --stop --user haproxy --pidfile "$PIDFILE" \
45
 
                || return 2
 
44
        if [ ! -f $PIDFILE ] ; then
 
45
                # This is a success according to LSB
 
46
                return 0
 
47
        fi
 
48
        for pid in $(cat $PIDFILE) ; do
 
49
                /bin/kill $pid || return 4
 
50
        done
 
51
        rm -f $PIDFILE
46
52
        return 0
47
53
}
48
54
 
49
55
haproxy_reload()
50
56
{
51
 
        $HAPROXY -f "$CONFIG" -p $PIDFILE -D $EXTRAOPTS -st $(<$PIDFILE) \
 
57
        $HAPROXY -f "$CONFIG" -p $PIDFILE -D $EXTRAOPTS -sf $(cat $PIDFILE) \
52
58
                || return 2
53
59
        return 0
54
60
}
55
61
 
 
62
haproxy_status()
 
63
{
 
64
        if [ ! -f $PIDFILE ] ; then
 
65
                # program not running
 
66
                return 3
 
67
        fi
 
68
 
 
69
        for pid in $(cat $PIDFILE) ; do
 
70
                if ! ps --no-headers p "$pid" | grep haproxy > /dev/null ; then
 
71
                        # program running, bogus pidfile
 
72
                        return 1
 
73
                fi
 
74
        done
 
75
 
 
76
        return 0
 
77
}
 
78
 
 
79
 
56
80
case "$1" in
57
81
start)
58
82
        log_daemon_msg "Starting haproxy" "haproxy"
59
83
        haproxy_start
60
 
        case "$?" in
 
84
        ret=$?
 
85
        case "$ret" in
61
86
        0)
62
87
                log_end_msg 0
63
88
                ;;
69
94
                log_end_msg 1
70
95
                ;;
71
96
        esac
 
97
        exit $ret
72
98
        ;;
73
99
stop)
74
100
        log_daemon_msg "Stopping haproxy" "haproxy"
75
101
        haproxy_stop
76
 
        case "$?" in
 
102
        ret=$?
 
103
        case "$ret" in
77
104
        0|1)
78
105
                log_end_msg 0
79
106
                ;;
81
108
                log_end_msg 1
82
109
                ;;
83
110
        esac
 
111
        exit $ret
84
112
        ;;
85
113
reload|force-reload)
86
114
        log_daemon_msg "Reloading haproxy" "haproxy"
110
138
                ;;
111
139
        esac
112
140
        ;;
 
141
status)
 
142
        haproxy_status
 
143
        ret=$?
 
144
        case "$ret" in
 
145
        0)
 
146
                echo "haproxy is running."
 
147
                ;;
 
148
        1)
 
149
                echo "haproxy dead, but $PIDFILE exists."
 
150
                ;;
 
151
        *)
 
152
                echo "haproxy not running."
 
153
                ;;
 
154
        esac
 
155
        exit $ret
 
156
        ;;
113
157
*)
114
 
        echo "Usage: /etc/init.d/haproxy {start|stop|reload|restart}"
115
 
        exit 3
 
158
        echo "Usage: /etc/init.d/haproxy {start|stop|reload|restart|status}"
 
159
        exit 2
116
160
        ;;
117
161
esac
118
162