Rtorrent Boot with System

das329717

Member
May 25, 2018
928
0
16
For some reason Cron doesn't start rtorrent with boot. Anyone know why?

From Crontab:
@reboot /usr/bin/screen -dm rtorrent -n -o import=/home/lotus22/.rtorrent.rc

I can run that on a terminal screen and it runs fine. I don't know why it's not working with boot.
 

shwetha17

Member
May 24, 2018
785
0
16
This would depend on many things, first of all being which Distro.

Second thing, it's ALWAYS better to make a script and use THAT in cron. For instance, here is the one i use on FreeBSD to check space and start rtorrent if it is not full:

Code:
#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
SERVICE='rtorrent'
FILE="/usr/home/$USER/rtorrent/.session/rtorrent.lock"

df /usr/home/$USER| tail -1 | while read fs size used avail pcnt mount;
do
pcnt=$(echo ${pcnt} | cut -d'%' -f1 )
if [ ${pcnt} -ge 95 ]; then
echo "Running out of space \"${fs} (${pcnt}%)\" on ${HOSTNAME} as on $(date)"
exit 1
fi

if pgrep -u $USER $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
rm -f ${FILE}
echo "$SERVICE is not running, starting $SERVICE"| screen -d -m -S seedbox $SERVICE
fi
done



and this is my crontab:


@reboot /usr/local/bin/chkrtorrent >/dev/null 2>&1
*/5 * * * * /usr/local/bin/chkrtorrent >/dev/null 2>&1



but, depending on your distro, you may need to add the user to a cron group OR you may need to add them to a file in /etc

which distro are you using?
 

das329717

Member
May 25, 2018
928
0
16
I was looking at doing the script way and that's how I had it setup for Rutorrent 2.8 and Rtorrent 0.8.4

Ubuntu 9.04


I'll take a look at your script and get back to you... Thanks for the help.
 

shwetha17

Member
May 24, 2018
785
0
16
I'm not sure my script works in ubuntu.

I think ubuntu has a cron user group. This may be your issue. I know you don't need to call the .rtorrent.rc part. just create a new ubuntu user, put the .rtorrent.rc in thier home directory, make sure that user has cron permissions (i think it's the GROUP cron) then log in ad that user and do crontab -e
 

jith45

Member
May 25, 2018
960
0
16
heres my rtorrent startup script.
It starts rtorrent in a screen session.
You'll need to change the user variable to the user name you want to run rtorrent with

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 (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
##############
###</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
user="subvert"

# 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="`su -c 'echo $HOME' $user`/.rtorrent.rc"

# set of options to run with
options=""

# default directory for screen, needs to be an absolute path
base="`su -c 'echo $HOME' $user`"

# name of screen session
srnname="rtorrent"

# file to log to (makes for easier debugging if something goes wrong)
logfile="/var/log/rtorrentInit.log"
#######################
###END CONFIGURATION###
#######################
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 "$logfile" >&2
# 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\"" ${user} | tee -a "$logfile" >&2
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=`cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//" `
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

Im running karmic (9.10) server, but this should do fine on Jaunty also.

Should be put in /etc/init.d/ and must be made executable.

You also need to register it:

Code:
sudo update-rc.d /etc/init.d/rtorrent defaults
 

shwetha17

Member
May 24, 2018
785
0
16
i posted my cron script in antoehr spot in the forums. It not only starts rutorrent but it also checks space, if the hard drive is too close to full, it doesn't start. This is really good to use with the auto-stop function. alos it helps keep rtorrent running even in crash situations.
 

somus1735

Member
May 25, 2018
833
0
16
when i run that script under debian, it believes rtorrent is already running

Code:
if pgrep -u $USER $SERVICE > /dev/null
is returning two pid's that arent existent when the script exits.
 

dsouvik215

Member
May 25, 2018
896
0
16
hi,

i just try your excellent script, make executable etc ...

but when i try it :

Quote
/home# /etc/init.d/rtorrent start
cannot find readable config /home/creips/.rtorrent.rc. check that it is there and permissions are appropriate​


but i think all permission is good ?

Quote
193844:/home# chown -R creips:creips creips
193844:/home# ls -la
total 16
drwxr-xr-x 4 root root 4096 Oct 30 17:21 .
drwxr-xr-x 21 root root 4096 Oct 30 17:08 ..
drwxr-xr-x 2 creips creips 4096 Oct 30 18:00 creips
drwxr-xr-x 3 root root 4096 Oct 30 17:21 downloads​


need help :'(
 

shwetha17

Member
May 24, 2018
785
0
16
it could be a number of things.

some linux distros require the user to belong to the crontab (or cron) group

some have a file called /etc/cron.allow

some have a file called /etc/cron.disable

check your distro's documentation.
 

jith45

Member
May 25, 2018
960
0
16
I used both wonslung's script and the subsy one to start rtorrent at startup and make a cronjob to check it is runnning.

However now 2 of my rtorrent user cannot access rutorrent even rtorrent is still running



the user htth got error message :
Code:
"bad link to rtorrent. Check if it is really running. Check $scgi_port and $scgi_host settings in config.php and scgi_port in rTorrent configuration file."
and the user dmh got error message:
Code:
03.11.2010 00:44:17] Bad link to rTorrent. Check if it is really running. Check $scgi_port and $scgi_host settings in config.php and scgi_port in rTorrent configuration file.
[03.11.2010 00:44:17] Bad response from server: (200 [parsererror,getuisettings]) {"webui.fls.view":0,"webui.show_cats":1,"webui.show_dets":1,"webui.needmessage":1,"webui.reqtimeout":30000,"webui.confirm_when_deleting":1,"webui.alternate_color":0,"webui.update_interval":3000,"webui.hsplit":0.88,"webui.vsplit":0.5,"webui.effects":0,"webui.fullrows":0,"webui.no_delaying_draw":1,"webui.search":-1,"webui.speedlistdl":"100,150,200,250,300,350,400,450,500,750,1000,1250","webui.speedlistul":"100,150,200,250,300,350,400,450,500,750,1000,1250","webui.ignore_timeouts":0,"webui.retry_on_error":120,"webui.lang":"en","webui.trt.colwidth":[340,100,60,100,1
Can you help me ?
 

somus1735

Member
May 25, 2018
833
0
16
does every user still have his own rtorrent.rc ?
All with different ports ?
And are these ports put in the users config file ?
 

shwetha17

Member
May 24, 2018
785
0
16
you've done something wrong. As rasc said, you need to make sure the settings are correct.

A startup script isn't going to solve your shitty settings, it will just start rtorrent settings-be-damned.
 

jith45

Member
May 25, 2018
960
0
16
Quote
does every user still have his own rtorrent.rc ?
All with different ports ?
And are these ports put in the users config file ?


I checked everything and sure that all I did right, and the problem is suddenly it crash, the day before my users still using their rtorrent normally but after 1 day they crash, 1 after 1
I tried to reboot but cannot solve
 

shwetha17

Member
May 24, 2018
785
0
16
yah, you're missing something.

cron should be pretty trival to get working.


Like i said, make sure each user is in the crontab group.