tor/debian/tor.init

106 lines
2.1 KiB
Plaintext
Raw Normal View History

2004-01-13 14:40:00 +01:00
#! /bin/sh
set -e
2004-01-13 14:40:00 +01:00
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/tor
2004-01-13 14:40:00 +01:00
NAME=tor
DESC="tor daemon"
TORPID=/var/run/tor/tor.pid
DEFAULTSFILE=/etc/default/$NAME
2005-02-02 07:49:07 +01:00
WAITFORDAEMON=35
ARGS=""
MAX_FILEDESCRIPTORS=4096
2004-01-13 14:40:00 +01:00
test -x $DAEMON || exit 0
# Include tor defaults if available
if [ -f $DEFAULTSFILE ] ; then
. $DEFAULTSFILE
2004-01-13 14:40:00 +01:00
fi
wait_for_deaddaemon () {
pid=$1
sleep 1
if test -n "$pid"
then
if kill -0 $pid 2>/dev/null
then
echo -n "."
cnt=0
while kill -0 $pid 2>/dev/null
do
cnt=`expr $cnt + 1`
if [ $cnt -gt $WAITFORDAEMON ]
then
echo " FAILED."
return 1
fi
sleep 1
echo -n "."
done
fi
fi
return 0
}
2004-01-13 14:40:00 +01:00
case "$1" in
start)
if [ "$RUN_DAEMON" != "yes" ]; then
echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
2004-01-13 14:40:00 +01:00
else
2004-11-12 18:34:02 +01:00
echo "Starting $DESC: $NAME..."
ulimit -n $MAX_FILEDESCRIPTORS
2004-01-13 14:40:00 +01:00
start-stop-daemon --start --quiet --oknodo \
--chuid debian-tor:debian-tor \
--pidfile $TORPID \
--exec $DAEMON -- $ARGS
echo "done."
2004-01-13 14:40:00 +01:00
fi
;;
stop)
echo -n "Stopping $DESC: "
pid=`cat $TORPID 2>/dev/null` || true
if test ! -f $TORPID -o -z "$pid"
then
echo "not running (there is no $TORPID)."
2005-02-02 07:49:07 +01:00
elif start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON
then
wait_for_deaddaemon $pid
echo "$NAME."
elif kill -0 $pid 2>/dev/null
then
echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
else
echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
fi
2004-01-13 14:40:00 +01:00
;;
reload|force-reload)
echo -n "Reloading $DESC configuration: "
pid=`cat $TORPID 2>/dev/null` || true
if test ! -f $TORPID -o -z "$pid"
then
echo "not running (there is no $TORPID)."
elif start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
then
echo "$NAME."
elif kill -0 $pid 2>/dev/null
then
echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
else
echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
fi
2004-01-13 14:40:00 +01:00
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
exit 1
;;
esac
exit 0