#!/bin/sh
#
# chkconfig: - 91 15
# description: Pound is a reverse proxy, load balancer and HTTPS front-end
# processname: pound
# config: /etc/pound/pound.cfg
# pidfile: /var/run/pound.pid

POUNDLIC="/etc/opt/nec/wbmc/lbpound.lic"
SSLSET=`/bin/grep main_sslacc_host_port /etc/iplb4.d/lbssl.dat | awk '{printf("%s%s%s%s,",$4,$5,$6,$10)}'`
expr "${SSLSET}" : '[0-9,.:]*111[0-9.]*:[0-9]*' > /dev/null 2>&1
SSLFLG=$?
PSPOUND=`/bin/ps -ef | /bin/grep pound | /bin/grep nobody`

start() {
    MAX_CONNECTIONS=`/bin/grep 'main_sslacc_max_connections' /etc/iplb4.d/lbssl.dat |perl -p -i -e "s/main_sslacc_max_connections\s+(\d+)\s+/\1/"`
    MAX_CONNECTIONS=`expr $MAX_CONNECTIONS + 10`
    if [ "$MAX_CONNECTIONS" != "" ];then
        ulimit -n $MAX_CONNECTIONS
    fi
    if [ -f $POUNDLIC ] && [ "$SSLSET" != "" ] && [ "$SSLFLG" == "0" ]; then
        /sbin/service pound start
    fi
}

stop() {
    if [ "$PSPOUND" != "" ]; then
        /sbin/service pound stop
    fi
}

restart() {
  stop
  start
}

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart)
    restart
    ;;
  *)
    echo $"Usage: $BASENAME {start|stop|restart}"
    RETVAL=1
esac
 
exit $RETVAL

