#!/bin/sh # chkconfig: 35 98 10 # description: blackhole generic TCP connection proxy # processname: conproxy # pidfile: /var/run/conproxy.pid cd / PIDFILE=/var/run/conproxy.pid SUBSYS=/var/lock/subsys/conproxy NAME=conproxy OPTIONFILE=/etc/conproxy-options.conf UNIXSOCK=/var/run/blackhole/conproxy.sock UNIXSOCKOLD=/var/run/blackhole/old/conproxy.sock case "$1" in start) MAXHANDLES=2000 CONPROXYOPTIONS= if [ -f $OPTIONFILE ] ; then . $OPTIONFILE fi mkdir -p /var/run/blackhole echo -n "Starting $NAME: " ulimit -n $MAXHANDLES; /usr/sbin/$NAME --maxhandles $MAXHANDLES --daemon $CONPROXYOPTIONS echo $NAME touch $SUBSYS ;; stop) echo -n "Stopping $NAME: " if [ -f $PIDFILE ] ; then kill `cat $PIDFILE` rm -f $SUBSYS rm -f $PIDFILE echo "$NAME" else echo fi ;; restart) # When we restart, we keep the old process around since it may have some # active connections # In some cases, the old is still alive, so we search a new name # We put the old socket in the /var/run/blackhole/old and allow # user blackhole to write into this directory, so conproxy # can remove the socket when ending mkdir -p /var/run/blackhole/old chown blackhole.blackhole /var/run/blackhole/old OLD=old0 N=0 while true do if [ ! -S $UNIXSOCKOLD.$OLD ] ; then mv -f $UNIXSOCK $UNIXSOCKOLD.$OLD break else N=`expr $N + 1` OLD=old$N fi done $0 start # Now there is a new conproxy running # Check if the old one still has connections NBCON=`conproxy-control --port $UNIXSOCKOLD.$OLD connections | wc -l` if [ "$NBCON" != 0 ] ; then echo "Old conproxy process still has $NBCON active connection(s), kept running" else echo "Old conproxy process ending" fi conproxy-control --port $UNIXSOCKOLD.$OLD quitlast $UNIXSOCKOLD.$OLD ;; reload) echo Nothing to reload ;; status) if [ ! -f $PIDFILE ] ; then echo Service $NAME is not running elif ! kill -0 `cat $PIDFILE` ; then echo Service $NAME is not running echo Unclean shutdown else echo Service $NAME is running conproxy-control status fi ;; *) echo "Usage: $NAME {start|stop|restart|reload|status}" exit 1 esac exit 0