summaryrefslogtreecommitdiff
path: root/tools/pingctl
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2003-06-06 10:04:47 +0000
committerPeter Palfrader <peter@palfrader.org>2003-06-06 10:04:47 +0000
commitee38573c402333971e7cf873b2fbcd1865206505 (patch)
treebed93e7ffc4bf2108ced79ccfda0267c65296546 /tools/pingctl
parent62c859444ceb4401f6e73c48f4d6035f26646830 (diff)
Remove random command invocation via pingctr/init script. People should just call pingd directly
Diffstat (limited to 'tools/pingctl')
-rwxr-xr-xtools/pingctl59
1 files changed, 46 insertions, 13 deletions
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 <COMMAND> [parameters]" >&2
- echo "See the pingd(1) manual page for valid commands" >&2
exit 1
;;
esac