5 # Required-Start: $remote_fs $network
6 # Required-Stop: $remote_fs
9 # Default-Start: 2 3 4 5
11 # Short-Description: apt helper for peer-to-peer downloads of Debian packages
12 # Description: Apt-p2p is a helper for downloading Debian packages
13 # files with APT. It will download any needed files from
14 # other Apt-p2p peers in a bittorrent-like manner, and so
15 # reduce the strain on the Debian mirrors.
18 # /etc/init.d/apt-p2p: start and stop the apt-p2p daemon
20 PATH=/sbin:/bin:/usr/sbin:/usr/bin
22 rundir=/var/run/apt-p2p/
23 pidfile=$rundir/apt-p2p.pid
24 logfile=/var/log/apt-p2p.log
25 application=/usr/sbin/apt-p2p
26 twistd=/usr/bin/twistd
31 [ -r /etc/default/apt-p2p ] && . /etc/default/apt-p2p
33 test -x $twistd || exit 0
34 test -r $application || exit 0
38 *) echo -n "Value of 'enable' in /etc/default/apt-p2p must be either 'true' or 'false'; "
39 echo "not starting apt-p2p daemon."
44 # return true if at least one pid is alive
51 if kill -0 $i 2> /dev/null; then
63 echo -n "Starting apt-p2p"
64 [ ! -d $rundir ] && mkdir $rundir
65 [ ! -f $logfile ] && touch $logfile
66 chown $user $rundir $logfile
67 [ -f $pidfile ] && chown $user $pidfile
68 # Make cache files readable
70 start-stop-daemon --start --quiet --exec $twistd -- \
71 --pidfile=$pidfile --rundir=$rundir --python=$application \
72 --logfile=$logfile --no_save
75 echo "apt-p2p daemon not enabled in /etc/default/apt-p2p, not starting..."
80 echo -n "Stopping apt-p2p"
81 start-stop-daemon --stop --quiet --pidfile $pidfile
83 # Continue stopping until daemon finished or time over
86 pid=$(cat $pidfile 2>/dev/null)
88 if [ $count -gt 20 ]; then
91 elif [ $count = 1 ]; then
92 echo -n " [wait $count"
93 elif [ $count -gt 1 ]; then
96 count=$(expr $count + 1)
98 start-stop-daemon --stop --quiet --pidfile $pidfile
100 if [ $count -gt 1 ]; then
116 echo "Usage: /etc/init.d/apt-p2p {start|stop|restart|force-reload}" >&2