From ee38573c402333971e7cf873b2fbcd1865206505 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Fri, 6 Jun 2003 10:04:47 +0000 Subject: Remove random command invocation via pingctr/init script. People should just call pingd directly --- tools/pingctl | 59 ++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 46 insertions(+), 13 deletions(-) (limited to 'tools') diff --git a/tools/pingctl b/tools/pingctl index 9304734..ba99c19 100755 --- a/tools/pingctl +++ b/tools/pingctl @@ -10,7 +10,9 @@ set -e USER=pinger VERBOSE=0 -PINGD="/home/pinger/echolot/pingd" +BASEDIR="/home/pinger/echolot" +PINGD="$BASEDIR/pingd" +PIDFILE="$BASEDIR/pingd.pid" # You probably don't want to mess with stuff below this line ################################################################ @@ -18,6 +20,35 @@ PINGD="/home/pinger/echolot/pingd" CHECKULIMIT=1 CHECKUID=1 + +wait_for_deaddaemon () { + PID=$1 + sleep 3 + if test -n "$PID" + then + if kill -0 $PID 2>/dev/null + then + echo -n "Waiting for pid $PID ." + cnt=0 + while kill -0 $PID 2>/dev/null + do + cnt=`expr $cnt + 1` + if [ $cnt -gt 30 ] + then + echo -n " Failed.. " + break + fi + sleep 2 + echo -n "." + done + rm -f $PIDFILE + else + rm -f $PIDFILE + fi + fi +} + + # Check for evil ulimits if [ "$CHECKULIMIT" -gt "0" ]; then FDs=`ulimit -n` @@ -70,6 +101,18 @@ fi case $1 in start) + if [ -f $PIDFILE ] ; then + PID=`cat $PIDFILE 2>/dev/null` || true + if kill -0 $PID 2>/dev/null + then + echo "pingd already running." + exit 0 + else + echo -n "Removing stale pid file: " + rm -f $PIDFILE + echo "$PIDFILE." + fi + fi echo -n "Starting Echolot: pingd" if [ ! -z "$SU" ]; then $SU "$PINGD --detach $VERBOSE start" @@ -90,23 +133,13 @@ stop) ;; reload|force-reload|restart) + PID=`cat $PIDFILE 2>/dev/null` || true $0 stop - sleep 10 + wait_for_deaddaemon $PID $0 start ;; -process|add|delete|set|setremailercaps|deleteremailercaps|getkeyconf|sendpings|sendchainpings|buildstats|buildkeys|buildthesaurus|buildfromlines|dumpconf|summary) - echo "Running pingd $1..." - if [ ! -z "$SU" ]; then - $SU "$PINGD \"$@\"" - else - $PINGD "$@" - fi - echo "done." - ;; *) echo "Usage: $0 (start|stop|reload|force-reload|restart)" >&2 - echo " $0 [parameters]" >&2 - echo "See the pingd(1) manual page for valid commands" >&2 exit 1 ;; esac -- cgit v1.2.3