Pull to refresh

установка rTorrent+wTorrent на Ubuntu 8.10

Reading time5 min
Views1.5K
Мой домашний сервер включен 24х7. А по ночам он простаивает, захотелось его чем нибудь нагрузить. Чем можно нагрузить домашний сервер с безлимитным интернетом — понятное дело торрентами. А поскольку сервер на линуксе, то и торрент клиент нужно искать консольный и с Web интерфейсом

И мой взгляд упал на rTorrent + wTorrent. Долго гугля в различных интернетах понял, что большинство пытается поднять эту связку на вебсервере Лайти (lighttpd), а вот под апач к сожалению нет толковых мануалов.
Чтож, попробую написать свой мануал

итак начнем

ставим необходимые пакеты

apt-get install rtorrent screen apache2 php5-cgi php5-common php5-sqlite php5-xmlrpc sqlite unzip php5-curl

тут следует отметить что пакет rtorrent для Ubuntu идет уже скомпилирован с xmlrpc для Debian Etch придется собирать самому, либо использовать версию пакета из тестинга

итак займемся настройкой пакета rTorrent. следует отметить что rTorrent нужно запускать от учетки пользователя. в моем случае это была учетная запись randomtoy

в папке /home/randomtoy создаем файл .rtorrent.rc со следующим содержанием

scgi_port = localhost:5000
min_peers = 40
max_peers = 100
min_peers_seed = 10
max_peers_seed = 50
max_uploads = 15
#upload_rate = 50
directory = /home/randomtoy/torrents/doing
session = /home/randomtoy/torrents/.rtsession/
schedule = watch_directory,5,5,load_start=/home/randomtoy/torrents/watch/*.torrent
schedule = tied_directory,5,5,start_tied=
schedule = untied_directory,5,5,close_untied=
on_finished = move_complete,"execute=mv,-u,$d.get_base_path=,/home/randomtoy/torrents/done/ ;d.set_directory=/home/randomtoy/torrents/done/"
on_start = link1,"create_link=tied,,.started"
on_stop = link1,"delete_link=tied,,.started"
on_finished = link1,"create_link=tied,,.finished"
on_erase = link1,"delete_link=tied,,.finished"
schedule = low_diskspace,5,60,close_low_diskspace=100M
#schedule = ratio,60,60,"stop_on_ratio=120,200M,2000"
port_range = 10000-10001
port_random = no
check_hash = yes
use_udp_trackers = yes
encryption = allow_incoming,try_outgoing,enable_retry
dht = auto
dht_port = 63982


тут же создаем следующие директории

torrents
torrents/watch
torrents/doing
torrents/done
torrents/.rtsession

запускаем rtorrent, если нет ошибок, продолжаем. Следующая проблема. как запускать рторрент от пользователя при запуске системы?
создаем скрипт rtorrent со следующим содержимым
#!/bin/bash

### BEGIN INIT INFO
# Provides: rtorrent
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start rtorrent as a daemon
### END INIT INFO

#!/bin/sh
#############
######
#############
# This script depends on screen.
# For the stop function to work, you must set an
# explicit session directory using ABSOLUTE paths (no, ~ is not absolute) in your rtorrent.rc.
# If you typically just start rtorrent with just "rtorrent" on the
# command line, all you need to change is the "user" option.
# Attach to the screen session as your user with
# "screen -dr rtorrent". Change "rtorrent" with srnname option.
# Licensed under the GPLv2 by lostnihilist: lostnihilist _at_ gmail _dot_ com
##############
######
##############

#######################
##Start Configuration##
#######################
# You can specify your configuration in a different file
# (so that it is saved with upgrades, saved in your home directory,
# or whateve reason you want to)
#Do not put a space on either side of the equal signs e.g.
# user = user
# will not work
# system user to run as
user="randomtoy"

# the system group to run as, not implemented, see d_start for beginning implementation
# group=`id -ng "$user"`

# the full path to the filename where you store your rtorrent configuration
config="/home/randomtoy/.rtorrent.rc"

# set of options to run with
options=""

# default directory for screen, needs to be an absolute path
#base="/home/${user}"
base="/home/randomtoy"

# name of screen session
srnname="rtorrent"

# file to log to (makes for easier debugging if something goes wrong)
logfile="/var/log/rtorrentInit.log"
#######################
PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin
DESC="rtorrent"
NAME=rtorrent
DAEMON=$NAME
SCRIPTNAME=/etc/init.d/$NAME

checkcnfg() {
exists=0
for i in `echo "$PATH" | tr ':' '\n'` ; do
if [ -f $i/$NAME ] ; then
exists=1
break
fi
done
if [ $exists -eq 0 ] ; then
echo "cannot find rtorrent binary in PATH $PATH" | tee -a "$logfile" >&2
exit 3
fi
if ! [ -r "${config}" ] ; then
echo "cannot find readable config ${config}. check that it is there and permissions are appropriate" | tee -a "$logfile" >&2
exit 3
fi
# session=`getsession "$config"`
# if ! [ -d "${session}" ] ; then
# echo "cannot find readable session directory ${session} from config ${config}. check permissions" | tee -a "$logfile" >&2
# exit 3
# fi
}
d_start() {
[ -d "${base}" ] && cd "${base}"
stty stop undef && stty start undef
su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "screen -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$log$
# this works for the screen command, but starting rtorrent below adopts screen session gid
# even if it is not the screen session we started (e.g. running under an undesirable gid
#su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "sg \"$group\" -c \"screen -fn -dm -S ${srnname} 2>&1 1>/dev/null$
su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2
}

d_stop() {
session=`getsession "$config"`
if ! [ -s ${session}/rtorrent.lock ] ; then
return
fi
pid=`cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g"`
if ps -A | grep -sq ${pid}.*rtorrent ; then # make sure the pid doesn't belong to another process
kill -s INT ${pid}
fi
}

getsession() {
session=`awk '/^[[:space:]]*session[[:space:]]*=[[:space:]]*/{print($3)}' "$config"`
echo $session
}

checkcnfg
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart|force-reload)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 1
;;
esac

exit 0



копируем скрипт, делаем его выполняемым и добавляем в автозагрузку

cp rtorrent /etc/init.d

chmod a+x /etc/init.d/rtorrent

update-rc.d rtorrent defaults 25



Теперь rtorrent будет запускаться в screen при запуске системы

ну и теперь приступаем к самому вкусному, к Web-интерфейсу. из различных вебморд я выбрал, основанную на аяксе wTorrent

скачиваем wTorrent

cd /var/www

rm -f index.html

svn co svn://canbruixa.homelinux.net/repos/trunk/wtorrent/

cd wtorrent

mv * ..

mv .* ..

cd ..

rmdir wtorrent

touch ./db/database.db

chown -R www-data:www-data db torrents tpl_c



Вот теперь мы дошли до настройки Apache.

выполняем в консоли
a2enmod scgi_module

в файл апача /etc/apache2/sites-avaible/default добавляем

SCGIMount /RPC2 127.0.0.1:5000


перезапускаем rtorrent и Апач
/etc/init.d/rtorrent restart
/etc/init.d/apache2 restart


заходим на страницу localhost/install.php

создаем аккаунт администраторатора

заходим по адресу localhost

вуаля. wTorrent работает
Tags:
Hubs:
+9
Comments40

Articles

Change theme settings