5 # Required-Start: $network
9 # Default-Start: 2 3 4 5
11 # Short-Description: apt helper for peer-to-peer downloads of Debian packages
12 # Description: Apt-DHT is a helper for downloading Debian packages
13 # files with APT. It will download any needed files from
14 # other Apt-DHT peers in a bittorrent-like manner, and so
15 # reduce the strain on the Debian mirrors.
18 # /etc/init.d/apt-dht: start and stop the apt-dht daemon
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin
22 rundir=/var/run/apt-dht/
23 pidfile=$rundir/apt-dht.pid
24 logfile=/var/log/apt-dht.log
25 application=/usr/sbin/apt-dht
26 twistd=/usr/bin/twistd
30 [ -r /etc/default/apt-dht ] && . /etc/default/apt-dht
32 test -x $twistd || exit 0
33 test -r $application || exit 0
35 # return true if at least one pid is alive
42 if kill -0 $i 2> /dev/null; then
53 echo -n "Starting apt-dht"
54 [ ! -d $rundir ] && mkdir $rundir
55 [ ! -f $logfile ] && touch $logfile
56 chown $user $rundir $logfile
57 [ -f $pidfile ] && chown $user $pidfile
58 # Make cache files readable
60 start-stop-daemon --start --quiet --exec $twistd -- \
61 --pidfile=$pidfile --rundir=$rundir --python=$application \
62 --logfile=$logfile --no_save
67 echo -n "Stopping apt-dht"
68 start-stop-daemon --stop --quiet --pidfile $pidfile
70 # Continue stopping until daemon finished or time over
73 pid=$(cat $pidfile 2>/dev/null)
75 if [ $count -gt 20 ]; then
78 elif [ $count = 1 ]; then
79 echo -n " [wait $count"
80 elif [ $count -gt 1 ]; then
83 count=$(expr $count + 1)
85 start-stop-daemon --stop --quiet --pidfile $pidfile
87 if [ $count -gt 1 ]; then
103 echo "Usage: /etc/init.d/apt-dht {start|stop|restart|force-reload}" >&2