updated on Sat Jan 14 16:01:55 UTC 2012
[aur-mirror.git] / haproxy / haproxy.init
blob556e225755d13d60ae385b18c1e287658f8ac91a
1 #!/bin/bash
3 maxconn=1014
4 daemon_name=haproxy
5 config=/etc/haproxy/haproxy.cfg
7 . /etc/rc.d/functions
9 . /etc/rc.conf
11 get_pid() {
12 cat /var/run/$daemon_name.pid 2> /dev/null
15 if [ -e "$config" ]; then
16 maintfd=`grep '^\([^#]*\)\(listen\|server\)' $config|wc -l`
17 else
18 maintfd=0
21 maxfd=$[$maxconn*2 + $maintfd]
22 if [ $maxfd -lt 100 ]; then
23 maxfd=100;
26 case "$1" in
27 start)
28 stat_busy "Starting $daemon_name daemon"
30 PID=`get_pid`
31 if [ -z "$PID" ]; then
32 [ -f /var/run/$daemon_name.pid ] && rm -f /var/run/$daemon_name.pid
33 ulimit -n $maxfd
34 /usr/sbin/$daemon_name -p /var/run/$daemon_name.pid -D -f $config -n $maxconn
35 if [ $? -gt 0 ]; then
36 echo -e "\n >> Make sure you start $daemon_name as the root user"
37 stat_fail
38 exit 1
39 else
40 stat_done
42 else
43 stat_fail
44 exit 1
48 stop)
49 stat_busy "Stopping $daemon_name daemon"
50 PID=`get_pid`
51 [ ! -z "$PID" ] && kill $PID &> /dev/null
52 if [ $? -gt 0 ]; then
53 stat_fail
54 exit 1
55 else
56 rm -f /var/run/$daemon_name.pid &> /dev/null
57 rm_daemon $daemon_name
58 stat_done
62 dump_status)
63 stat_busy "Dumping $daemon_name status in log file"
64 PID=`get_pid`
65 [ ! -z "$PID" ] && kill -HUP $PID &> /dev/null
66 if [ $? -gt 0 ]; then
67 stat_fail
68 exit 1
69 else
70 stat_done
74 restart)
75 $0 stop
76 sleep 3
77 $0 start
80 echo "usage: $0 {start|stop|stop_now|restart|dump_status}"
81 esac
82 exit 0