2005-11-15 11:28:00 +01:00
|
|
|
#! /bin/bash
|
2004-01-13 14:40:00 +01:00
|
|
|
|
2005-09-14 15:05:58 +02:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: tor
|
|
|
|
# Required-Start: $local_fs, $remote_fs, $network, $named, $time
|
|
|
|
# Required-Stop: $local_fs, $remote_fs, $network, $named, $time
|
|
|
|
# Should-Start: $syslog
|
|
|
|
# Should-Stop: $syslog
|
|
|
|
# Default-Start: 2 3 4 5
|
|
|
|
# Default-Stop: 0 1 6
|
|
|
|
# Short-Description: Starts The Onion Router daemon processes
|
2005-11-15 11:36:42 +01:00
|
|
|
# Description: Start The Onion Router, a TCP overlay
|
2005-09-14 15:05:58 +02:00
|
|
|
# network client that provides anonymous
|
|
|
|
# transport.
|
|
|
|
### END INIT INFO
|
|
|
|
|
2004-03-03 14:23:19 +01:00
|
|
|
set -e
|
|
|
|
|
2004-01-13 14:40:00 +01:00
|
|
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
2004-02-27 02:07:38 +01:00
|
|
|
DAEMON=/usr/sbin/tor
|
2004-01-13 14:40:00 +01:00
|
|
|
NAME=tor
|
|
|
|
DESC="tor daemon"
|
2005-08-09 15:11:00 +02:00
|
|
|
TORPIDDIR=/var/run/tor
|
|
|
|
TORPID=$TORPIDDIR/tor.pid
|
2004-03-03 14:23:19 +01:00
|
|
|
DEFAULTSFILE=/etc/default/$NAME
|
2005-03-10 19:19:14 +01:00
|
|
|
WAITFORDAEMON=60
|
2004-11-10 04:42:06 +01:00
|
|
|
ARGS=""
|
2006-01-23 16:04:03 +01:00
|
|
|
MAX_FILEDESCRIPTORS=8192
|
2005-02-04 13:25:39 +01:00
|
|
|
NICE=""
|
2004-01-13 14:40:00 +01:00
|
|
|
|
|
|
|
test -x $DAEMON || exit 0
|
|
|
|
|
|
|
|
# Include tor defaults if available
|
2004-03-03 14:23:19 +01:00
|
|
|
if [ -f $DEFAULTSFILE ] ; then
|
|
|
|
. $DEFAULTSFILE
|
2004-01-13 14:40:00 +01:00
|
|
|
fi
|
|
|
|
|
2004-03-03 14:23:19 +01:00
|
|
|
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
|
|
|
|
2006-08-29 22:43:59 +02:00
|
|
|
|
|
|
|
if test ! -d $TORPIDDIR; then
|
|
|
|
echo "There is no $TORPIDDIR directory. Creating one for you."
|
|
|
|
mkdir -m 02700 "$TORPIDDIR"
|
|
|
|
chown debian-tor:debian-tor "$TORPIDDIR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test ! -x $TORPIDDIR; then
|
|
|
|
echo "Cannot access $TORPIDDIR directory, are you root?" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
2004-01-13 14:40:00 +01:00
|
|
|
case "$1" in
|
|
|
|
start)
|
|
|
|
if [ "$RUN_DAEMON" != "yes" ]; then
|
2004-03-03 14:23:19 +01:00
|
|
|
echo "Not starting $DESC (Disabled in $DEFAULTSFILE)."
|
2006-08-29 22:43:59 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -n "$MAX_FILEDESCRIPTORS" ]; then
|
|
|
|
echo -n "Raising maximum number of filedescriptors (ulimit -n) to $MAX_FILEDESCRIPTORS"
|
|
|
|
if ulimit -n "$MAX_FILEDESCRIPTORS" ; then
|
|
|
|
echo "."
|
2005-08-09 15:11:00 +02:00
|
|
|
else
|
2006-08-29 22:43:59 +02:00
|
|
|
echo ": FAILED."
|
2005-08-09 15:11:00 +02:00
|
|
|
fi
|
2004-01-13 14:40:00 +01:00
|
|
|
fi
|
2006-08-29 22:43:59 +02:00
|
|
|
|
|
|
|
echo "Starting $DESC: $NAME..."
|
2007-06-01 02:42:13 +02:00
|
|
|
if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
|
2006-08-29 22:43:59 +02:00
|
|
|
echo "ABORTED: Tor configuration invalid:" >&2
|
2007-06-01 02:42:13 +02:00
|
|
|
su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
|
2006-08-29 22:43:59 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
start-stop-daemon --start --quiet --oknodo \
|
|
|
|
--chuid debian-tor:debian-tor \
|
|
|
|
--pidfile $TORPID \
|
|
|
|
$NICE \
|
|
|
|
--exec $DAEMON -- $ARGS
|
|
|
|
echo "done."
|
2004-01-13 14:40:00 +01:00
|
|
|
;;
|
|
|
|
stop)
|
|
|
|
echo -n "Stopping $DESC: "
|
2004-03-03 14:23:19 +01:00
|
|
|
pid=`cat $TORPID 2>/dev/null` || true
|
2006-08-29 22:43:59 +02:00
|
|
|
|
|
|
|
if test ! -f $TORPID -o -z "$pid"; then
|
2004-03-03 14:23:19 +01:00
|
|
|
echo "not running (there is no $TORPID)."
|
2006-08-29 22:43:59 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
if start-stop-daemon --stop --signal INT --quiet --pidfile $TORPID --exec $DAEMON; then
|
2004-03-03 14:23:19 +01:00
|
|
|
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
|
2004-07-08 03:22:06 +02:00
|
|
|
echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
|
2004-03-03 14:23:19 +01:00
|
|
|
fi
|
2004-01-13 14:40:00 +01:00
|
|
|
;;
|
|
|
|
reload|force-reload)
|
2004-03-03 14:23:19 +01:00
|
|
|
echo -n "Reloading $DESC configuration: "
|
|
|
|
pid=`cat $TORPID 2>/dev/null` || true
|
2006-08-29 22:43:59 +02:00
|
|
|
|
|
|
|
if test ! -f $TORPID -o -z "$pid"; then
|
2004-03-03 14:23:19 +01:00
|
|
|
echo "not running (there is no $TORPID)."
|
2006-08-29 22:43:59 +02:00
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2007-06-01 02:42:13 +02:00
|
|
|
if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
|
2006-08-29 22:43:52 +02:00
|
|
|
echo "ABORTED: Tor configuration invalid:" >&2
|
2007-06-01 02:42:13 +02:00
|
|
|
su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
|
2006-08-29 22:43:52 +02:00
|
|
|
exit 1
|
2006-08-29 22:43:59 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
if start-stop-daemon --stop --signal 1 --quiet --pidfile $TORPID --exec $DAEMON
|
2004-03-03 14:23:19 +01:00
|
|
|
then
|
|
|
|
echo "$NAME."
|
|
|
|
elif kill -0 $pid 2>/dev/null
|
|
|
|
then
|
|
|
|
echo "FAILED (Is $pid not $NAME? Is $DAEMON a different binary now?)."
|
|
|
|
else
|
2004-07-08 03:22:06 +02:00
|
|
|
echo "FAILED ($DAEMON died: process $pid not running; or permission denied)."
|
2004-03-03 14:23:19 +01:00
|
|
|
fi
|
2004-01-13 14:40:00 +01:00
|
|
|
;;
|
|
|
|
restart)
|
2007-06-01 02:42:13 +02:00
|
|
|
if ! su -s /bin/sh -c "$DAEMON --verify-config" debian-tor > /dev/null; then
|
2006-08-29 22:43:59 +02:00
|
|
|
echo "Restarting Tor ABORTED: Tor configuration invalid:" >&2
|
2007-06-01 02:42:13 +02:00
|
|
|
su -s /bin/sh -c "$DAEMON --verify-config" debian-tor >&2
|
2006-08-29 22:43:59 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2004-01-13 14:40:00 +01:00
|
|
|
$0 stop
|
|
|
|
sleep 1
|
|
|
|
$0 start
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Usage: $0 {start|stop|restart|reload|force-reload}" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
exit 0
|