Saturday, June 25, 2011

Run rTorrent on startup with screen and upstart

To Setup rTorrent to automatically start as a service/daemon, you'll need to install screen and create an Upstart job.

First is to install rTorrent and screen if you don't already have them:

~$ sudo apt-get install rtorrent screen

Once installed, you'll want to setup your rtorrent settings and ensure they work as expected before continuing (read more).

Next comes the upstart job script. Here's what I use:

description "ncurses BitTorrent client based on LibTorrent"

start on (local-filesystems and net-device-up and runlevel [2345])
stop on runlevel [016]

chdir /home/user

pre-start exec su user -c "mkdir -p .rtorrent/session"

    su user -c "screen -d -m -S rtorrent rtorrent"
end script

Replace each instance of user with your Ubuntu username. Save to /etc/init/rtorrent.conf and you're done. rTorrent should automatically start on subsequent system startups.

Update: Changed upstart script to automatically create session folder if it doesn't exist.

Viewing rTorrent's status

Since rTorrent is running in a detached screen process, you can view what's going on and basically use rTorrent by attaching to the process:

~$ screen -r rtorrent

To detach again, press Ctrl-a followed by d.

That's it . Enjoy!