Included into optware with http://trac.nslu2-linux.org/optware/changeset/6061
Please report any problems with script here!
There is a script which can be used to run rTorrent on system startup suggested here: http://libtorrent.rakshasa.no/wiki/RTorrentCommonTasks
So, I have slightly modified it and put in /opt/etc/init.d/S99rtorrent
It starts rtorrent as user p2p with configuration file located in /opt/etc/rtorrent.conf and working directory /opt/share/torrent
PHP Code:
# !/bin/sh
#############
###<Notes>###
#############
# 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.
##############
###</Notes>###
##############
#######################
##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)
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/etc/rtorrent.conf")
# Examples:
# config=("/home/user/.rtorrent.rc")
# config=("/home/user/.rtorrent.rc" "/mnt/some/drive/.rtorrent2.rc")
# config=("/home/user/.rtorrent.rc"
# "/mnt/some/drive/.rtorrent2.rc"
# "/mnt/another/drive/.rtorrent3.rc")
# set of options to run with each instance, separated by a new line
# must keep parentheses around the entire statement
#if no special options, specify with: ""
options=("-n -o import=/opt/etc/rtorrent.conf")
# 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")
# default directory for screen, needs to be an absolute path
#base="/home/${user}"
base="/opt/share/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 || exit 0
checkcnfg() {
for (( i=0 ; i < ${#config[@]} ; i++ )) ; do
if ! [ -r "${config[i]}" ] ; then
echo "cannot find readable config ${config[i]}. check that it is there and permissions are appropriate">&2
exit 3
fi
session=$(cat "${config[i]}" | grep "^[[:space:]]*session" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//")
if ! [ -d "${session}" ] ; then
echo "cannot find readable session directory ${session} from config ${config[i]}. check permissions">&2
exit 3
fi
done
}
d_start() {
logger "Starting."
[ -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}
for (( i=0 ; i < ${#options[@]} ; i++ )) ; do
sleep 3
su -c "screen -S "${srnname}" -X screen rtorrent ${options[i]}" ${user}
done
}
d_stop() {
for (( i=0 ; i < ${#config[@]} ; i++ )) ; do
session=$(cat "${config[i]}" | grep "^[[:space:]]*session" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//")
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
if ps -A | grep ${pid}.*rtorrent > /dev/null ; then
kill -s INT ${pid}
fi
done
}
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
Included into optware with http://trac.nslu2-linux.org/optware/changeset/6061
Please report any problems with script here!
Cool to hear rtorrent has been packaged!
Any chance the DHT patch could be included in the package?
See: http://tk.ttdpatch.net/~jdrexler/dht/
This will give trackerless torrents functionality.
thanks,
Pim.
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.
Here is a short instruction how to use rtorrent by user another than root.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
1) Create user:
If necessary:PHP Code:
adduser p2p
2) Add the following lines to ~/.profile:PHP Code:
ipkg install adduser
tty is unfortunately also a part of coreutils However,. Oleg included it already in the next version of his fw (after preview 8.8)PHP Code:
alias rt='su -c "screen -r" p2p'
chmod a+rw `tty`
stty start undef
stty stop undef
Don't forget to save changes:
3) This utility requires to have installed: screenPHP Code:
flashfs save && flashfs commit && flashfs enable && reboot
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.PHP Code:
ipkg install screen
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
6) when you want to attach to it use: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
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 itPHP Code:
rt
Last edited by al37919; 13-10-2008 at 16:21.
Please accept my apologies for my English...
My ps command hasn't any options.
[admin@suleyma root]$ ps -?
ps: illegal option -- ?
BusyBox v1.1.3 (2007.01.01-14:37+0000) multi-call binary
Usage: ps
That's the default ps that comes with the firmware, and is embedded in the flash. Install the procps package (ipkg install procps) to get a better ps.
If S99rtorrent uses ps with arguments it's a bit of an oversight. It should test what kind of ps it's dealing with. If the advanced ps becomes a requirement, the rtorrent package would have to require (or at least recommend) the procps package. Which would be a bit silly.
al37919, you don't need ps -A for that if block in your script. You can do this instead:
Code:grep rtorrent /proc/${pid}/cmdline && \ kill -s INT ${pid}
I've installed procps.
There is a mention of procps by wengi:http://wl500g.info/showthread.php?t=...unslung&page=4
Thanks for your quick response.Cron must be in the process list (ps) after a reboot.
Remark: If you installed procps you should execute:
Êîä: ps axf
It's just that I've had my WL-500g for quite a while now and so far I've haven't felt the need for the advanced ps. Installing it just for a ps -A, which can be accomplished in a more efficient manner anyway, is a bit overkill.
I think I quite agree with you.
Look below where a short instruction how to use rtorrent by user another than root.
What do you think about:
I've done it.ipkg install coreutils
Thanks for the comemnts. I changed the script posted above so that now it explicitly uses busybox's /bin/ps. So, there is no need now to install procps package, other than ps in it is much nicer than the standard one
I agree that coreutils is a big package, that should be installed here only to be able to use su. However, su is required to be able to start rtorrent as non-root user, and it is not included in our version of busybox. May be we can ask Oleg to include it in the future releases...
You dont't need install coreutils for su.
It's enough to install adduser.
I've removed coreutils now and reinstall adduser - su is working (executing).
It seems: ipkg -force-reinstall install adduser
To be on the safe side, after executed ipkg remove coreutils, I've reinstalled all installed packages by one line awk script taken somewhere from the Forum:
But now I have next records in my /opt/var/log/messages:/usr/bin/awk '/^Package:/{system("/opt/bin/ipkg install -force-reinstall -force-defaults " $2)}' /opt/lib/ipkg/status
I think that is result executing this code:Code:Nov 2 16:00:40 admin: Starting. Nov 2 16:00:40 su: + none admin:p2p Nov 2 16:00:40 su: + none admin:p2p Nov 2 16:00:43 su: + none admin:p2p
But the same was before install coreutils...Code:for (( i=0 ; i < ${#options[@]} ; i++ )) ; do sleep 3 su -c "screen -S "${srnname}" -X screen rtorrent ${options[i]}" ${user} done
I plan to test it as soon as possible. Of course, it depends on whether Oleg compiled rtorrent with --with-xmlrpc-c. Sure, I can compile my own and still test it, but for mass use it will still have to have it.
The entire XMLRPC support thingy is very interesting and I'm glad there are finally applications using it. Controlling rtorrent remotely would be the final bit of goodness.
Some more info:
http://rakshasa.no/pipermail/libtorr...ay/001154.html
LE: sorry, no XMLRPC support compiled in.
Last edited by wirespot; 25-11-2007 at 22:49.
last version in repository has been compiled with xmlrpc support
Ah, sorry then, I must be late upgrading.
BTW, don't try setting the scgi_port option with older rtorrent builds, you'll crash them.
Last edited by wirespot; 25-11-2007 at 22:59.