StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Run rtorrent on startup

Fri Jul 20, 2012 8:21 am

Right now I've got my Pi in another room hooked up just to router via Ethernet and I'm configuring it over VNC on my windows 7 machine. Mainly due to lack of inputs and displays, but I'd like that to be my eventual setup.

Anyway I've got rtorrent set up, but I would like for it to run at startup without logging in or having to connect to the vnc. How can I do this? Is there a way to do this and still view the program when I do log in to the vnc?

Thanks

User avatar
RaTTuS
Posts: 10703
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Run rtorrent on startup

Fri Jul 20, 2012 8:48 am

well it depends....
how many cats have you ....
seriously
...
never having used it
you are using the console version?
a couple of things you can do

1)
edit /etc/inittab
change
1:2345:respawn:/sbin/getty --noclear 38400 tty1
to be
1:2345:respawn:/bin/login -f pi tty1 </dev/tty1 >/dev/tty1 2>&1
^ change pi to be whatever usename you are using
this means that the 1st console session will automatically log you in as user pi

2)
edit
~/.bash_rc
~/ means your home directory
add right at the end
if [ $(tty) == /dev/tty1 ]; then
rtorrent
fi
this means that if bash sees that you are on console one it will launch rtorrent [change that to be what ever command you want/need].

now you can log in fine on other consoles [f2-f6] with no issues and if you stop the program on console 1 then you can carry on as normal - if you
exit
then it will re-run the program mentioned in the .bashrc file.

...
others will have different methods
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Re: Run rtorrent on startup

Fri Jul 20, 2012 10:15 am

Ok I did both of those things. I set it for to log into root, then I logged into root on my VNC thing. But when I looked at the task manager there's no rtorrent as there would be if I ran it normally in the terminal.

StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Re: Run rtorrent on startup

Sun Jul 22, 2012 9:25 am

I'm still having trouble with this. Does anyone have any suggestions?

User avatar
RaTTuS
Posts: 10703
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Run rtorrent on startup

Sun Jul 22, 2012 9:46 am

ssh into it and
sudo apt-get install pastebinit
w
and
ps axOT | pastebinit

who is logged in
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

StoopKid
Posts: 41
Joined: Thu Jul 19, 2012 5:41 am

Re: Run rtorrent on startup

Wed Jul 25, 2012 10:53 am

I am logged in as root, and that is the only user.
http://paste.debian.net/180559

User avatar
RaTTuS
Posts: 10703
Joined: Tue Nov 29, 2011 11:12 am
Location: North West UK
Contact: Twitter YouTube

Re: Run rtorrent on startup

Wed Jul 25, 2012 11:07 am

that pastebin is of no use for this problem
no need to log in as root, a normal user is fine
cat /etc/rc.local
cat /etc/inittab
tail ~/bashrc
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV

1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe

elatllat
Posts: 1337
Joined: Sat Dec 17, 2011 5:05 pm

Re: Run rtorrent on startup

Tue Aug 21, 2012 4:39 pm

The correct way to do this is with a service:
#!/bin/bash

#
#/etc/init.d/rtorrent
#

NAME=rtorrent
PID=$(pidof $NAME);

function start {
if [ "$PID" = "" ] ; then
echo "Starting $NAME...";
tmux new-session -d -n $NAME -s $NAME rtorrent
echo " Done.";
else
echo "$NAME is already running as $PID.";
fi
}

function stop {
if [ "$PID" != "" ] ; then
echo "Stoping $NAME...";
kill $PID;
TIMEOUT=30;
START=$( date +%s);
while [ $(( $( date +%s) - ${START} )) -lt ${TIMEOUT} ]; do
PID=$(tmux ls |grep rtorrent);
if [ "$PID" == "" ]; then break
else sleep 2
fi
done
if [ "$PID" != "" ] ; then
echo "Error: $NAME would not stop";
else
echo " Done.";
fi
else
echo "$NAME is was not running.";
fi
}

function status {
if [ "$PID" = "" ]; then
echo "$NAME is not running";
else
echo "$NAME is running with pid $PID";
fi
}

if [ "$1" = "start" ]; then
start
elif [ "$1" = "stop" ]; then
stop
elif [ "$1" = "restart" ]; then
stop
start
elif [ "$1" = "status" ]; then
status
else
echo " * Usage: /etc/init.d/$NAME [start|status|stop|restart]";
fi
then

Code: Select all

update-rc.d rtorrent defaults
service rtorrent start
You could use screen or run as an underprivileged or chrooted user, etc.

(indentation is killed by phpBB :( )
SBC with 32GB RAM: https://hardkernel.com

FAQ : https://raspberrypi.stackexchange.com

Unanswered: https://www.raspberrypi.org/forums/search.php?search_id=unanswered

Return to “Beginners”