willy tarreau | 5cbea6f | 2005-12-17 12:48:26 +0100 | [diff] [blame] | 1 | #!/bin/sh |
willy tarreau | 535ae7a | 2005-12-17 12:58:00 +0100 | [diff] [blame] | 2 | # |
| 3 | # config.rc sample with defaults : |
| 4 | # service haproxy |
| 5 | # config /etc/haproxy/haproxy.cfg |
| 6 | # maxconn 1024 |
| 7 | # |
| 8 | config="/etc/haproxy/haproxy.cfg" |
| 9 | maxconn=1024 |
willy tarreau | 5cbea6f | 2005-12-17 12:48:26 +0100 | [diff] [blame] | 10 | |
| 11 | bin=/usr/sbin/haproxy |
willy tarreau | 535ae7a | 2005-12-17 12:58:00 +0100 | [diff] [blame] | 12 | cmdline='$bin -D' |
willy tarreau | 5cbea6f | 2005-12-17 12:48:26 +0100 | [diff] [blame] | 13 | |
| 14 | . $ROOT/sbin/init.d/default |
| 15 | |
willy tarreau | 535ae7a | 2005-12-17 12:58:00 +0100 | [diff] [blame] | 16 | if [ -e "$config" ]; then |
| 17 | maintfd=`grep '^\([^#]*\)\(listen\|server\)' $config|wc -l` |
| 18 | else |
| 19 | maintfd=0 |
| 20 | fi |
| 21 | |
| 22 | maxfd=$[$maxconn*2 + $maintfd] |
| 23 | if [ $maxfd -lt 100 ]; then |
| 24 | maxfd=100; |
| 25 | fi |
| 26 | cmdline="$cmdline -n $maxconn -f $config" |
| 27 | ulimit -n $maxfd |
| 28 | |
| 29 | # to get a core when needed, uncomment the following : |
| 30 | # cd /var/tmp |
| 31 | # ulimit -c unlimited |
| 32 | |
| 33 | # soft stop |
willy tarreau | bc4e1fb | 2005-12-17 13:32:07 +0100 | [diff] [blame] | 34 | function do_stop { |
willy tarreau | 5cbea6f | 2005-12-17 12:48:26 +0100 | [diff] [blame] | 35 | pids=`pidof -o $$ -- $PNAME` |
| 36 | if [ ! -z "$pids" ]; then |
willy tarreau | 535ae7a | 2005-12-17 12:58:00 +0100 | [diff] [blame] | 37 | echo "Asking $PNAME to terminate gracefully..." |
willy tarreau | 5cbea6f | 2005-12-17 12:48:26 +0100 | [diff] [blame] | 38 | kill -USR1 $pids |
willy tarreau | 8337c6b | 2005-12-17 13:41:01 +0100 | [diff] [blame] | 39 | echo "(use kill $pids to stop immediately)." |
| 40 | fi |
| 41 | } |
| 42 | |
| 43 | # dump status |
| 44 | function do_status { |
| 45 | pids=`pidof -o $$ -- $PNAME` |
| 46 | if [ ! -z "$pids" ]; then |
| 47 | echo "Dumping $PNAME status in logs." |
| 48 | kill -HUP $pids |
| 49 | else |
| 50 | echo "Process $PNAME is not running." |
willy tarreau | 5cbea6f | 2005-12-17 12:48:26 +0100 | [diff] [blame] | 51 | fi |
| 52 | } |
| 53 | |
| 54 | main $* |
| 55 | |