here is updated version of S99rtorrent:
It is a little simplified, so that is it uses only one configuration file and only one line with options. Now it conforms to /bin/sh sintaxis and works reliably during startup.
UPDATE 1/2008: I keep this script for historic reference only, as current version of S99rtorrent included in the optware package has even better S99rtorrent. However, the microhowto below applies also to a new standard version.
PHP Code:
#! /bin/sh
# This script depends on screen.
# For the stop function to work, you must set an
# explicit session directory using absolute paths 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.
# See http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks
# Do not proceed unless some apps are available.
test -x /opt/bin/screen || exit 0
test -x /opt/bin/su -o -x /bin/su || exit 0
#######################
##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)
# by commenting out/deleting the configuration lines and placing them
# in a text file (say /home/user/.rtorrent.init.conf) exactly as you would
# have written them here (you can leave the comments if you desire
# and then uncommenting the following line correcting the path/filename
# for the one you used. note the space after the ".".
# . /etc/rtorrent.init.conf
#Do not put a space on either side of the equal signs e.g.
# user = user
# will not work
# system user to run as (can only use one)
# Add this user to /etc/passwd
user="p2p"
# the full path to the filename where you store your rtorrent configuration
# must keep parentheses around the entire statement, quotations around each config file
#config="/home/${user}/.rtorrent.rc"
config="/opt/home/${user}/.rtorrent.rc"
#config="/opt/etc/rtorrent.conf"
# Examples:
# config="/home/user/.rtorrent.rc"
# set of options to run with each instance
# if no special options, specify with: ""
# if rtorrent is started without options it will read it's config from ~/.rtorrent.rc
options=""
# Examples:
# starts one instance, sourcing both .rtorrent.rc and .rtorrent2.rc
# options="-o import=~/.rtorrent2.rc"
# starts two instances, ignoring .rtorrent.rc for both, and using
# .rtorrent2.rc for the first, and .rtorrent3.rc for the second
# we do not check for valid options
# options="-n -o import=~/.rtorrent2.rc" "-n -o import=~/rtorrent3.rc"
#options="-n -o import=/opt/etc/rtorrent.conf"
# default directory for screen, needs to be an absolute path
#base="/home/${user}"
base="/opt/home/torrent"
# name of screen session
srnname="rtorrent"
#######################
###END CONFIGURATION###
#######################
PATH=/opt/local/bin:/opt/sbin:/opt/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="rtorrent"
NAME=rtorrent
DAEMON=/opt/bin/$NAME
SCRIPTNAME=/opt/etc/init.d/S99rtorrent
# Gracefully exit if the package has been removed.
test -x $DAEMON || (logger -t rtorrent "no daemon" && exit 0)
checkcnfg() {
if ! [ -r "${config}" ] ; then
logger -t rtorrent "cannot find readable config ${config}. check that it is there and permissions are appropriate"
exit 3
fi
session=$(awk '/^[[:space:]]*session[[:space:]]*=[[:space:]]*/{print($3)}' "${config}")
if ! [ -d "${session}" ] ; then
logger -t rtorrent "cannot find readable session directory ${session} from config ${config}. check permissions"
exit 3
fi
}
d_start() {
[ -d "${base}" ] && cd "${base}"
stty stop undef && stty start undef
su -c "screen -ls | grep ".${srnname}[[:space:]]" > /dev/null" ${user} || su -c "screen -dm -S ${srnname}" ${user}
sleep 3
su -c "screen -S "${srnname}" -X screen rtorrent ${options}" ${user}
su -c "screen -S "${srnname}" -p 0 -X kill" ${user}
logger -t rtorrent "started."
}
d_stop() {
session=$(awk '/^[[:space:]]*session[[:space:]]*=[[:space:]]*/{print($3)}' "${config}")
pid=$(cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g")
# make sure the pid doesn't belong to another process
# skip the pid otherwise
grep rtorrent /proc/${pid}/cmdline > /dev/null && kill -s INT ${pid}
sleep 6s
logger -t rtorrent "stopped."
}
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
Here is a short instruction how to use rtorrent by user another than root.
1) Create user:
If necessary:
PHP Code:
ipkg install adduser
2) Add the following lines to ~/.profile:
PHP Code:
alias rt='su -c "screen -r" p2p'
chmod a+rw `tty`
stty start undef
stty stop undef
tty is unfortunately also a part of coreutils
However,. Oleg included it already in the next version of his fw (after preview 8.8)
Don't forget to save changes:
PHP Code:
flashfs save && flashfs commit && flashfs enable && reboot
3) This utility requires to have installed: screen
PHP Code:
ipkg install screen
and su. With su current situation is more complicated. The latest Oleg's firmware (1.9.2.7-8.7) includes /bin/su , so nothing have to be done. However if you have earlier version then su has to be installed. It is a part of adduser and coreutils packages.
4) Create configuration file in the p2p's user home directory ( ~/.rtorrent.rc ) based on /opt/home/rtorrent.conf
5) set correct ownership and permissions on the rtorrent working directories depending on which directories are written in ~/.rtorrent.rc file
PHP Code:
chown -R p2p:p2p /opt/share/torrent/work
chown -R p2p:p2p /opt/share/torrent/session
chown -R p2p:p2p /opt/share/torrent/dl
6) when you want to attach to it use:
P.S. This script has 1 small bug/feature. An extra screen window with /bin/sh is started which can be afterwards exited manually. Up to now nobody knows how to eliminate it