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!


  1. For some reason rtorrent not picking up .rtorrent.rc which in my home dir if i start this way.

    1. Works for me here. Did you remember to replace "user" in the upstart script with your username?

      Tested on Ubuntu 12.04 64-bit which never had rTorrent installed after a clean install.

  2. Does this track the pid so I can stop and restart the service? I have nearly the same script and I'm not able to do those.

    1. I'm not sure what you mean by "track the pid". AFAIK there's no need to do so.

      I think the answers here should be what you're looking for though: