Start rTorrent Automatically at Boot on Debian/Ubuntu
I tend to use ruTorrent as a front-end for rTorrent and so I like to have rTorrent start silently and automatically on boot. Most of the guides on this subject seem to suggest using an init script placed in /etc/init.d, but this is more complicated than it needs to be in my opinion. You can use start-stop-daemon instead which is much simpler and yields the same result. Here’s how.
First install dtach:
1 | sudo apt-get install dtach |
Then edit your /etc/rc.local file:
1 | sudo nano /etc/rc.local |
By default this file looks something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. exit 0 |
Add the following before exit 0, making sure to replace karl with the user as which you would like to run rTorrent, and /usr/local/bin/rtorrent with the location of rTorrent on your system (/usr/bin/rtorrent if you installed from the repo, /usr/local/bin/rtorrent if you compiled rTorrent from source with the default install path):
1 | start-stop-daemon --start --chuid karl --name rtorrent --exec /usr/bin/dtach -- -n /tmp/rtorrent.dtach /usr/local/bin/rtorrent |
Your /etc/rc.local should now look like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. start-stop-daemon --start --chuid karl --name rtorrent --exec /usr/bin/dtach -- -n /tmp/rtorrent.dtach /usr/local/bin/rtorrent exit 0 |
Press ctrl+o to save the file and ctrl+x to quit nano.
That’s it! To test you can either reboot, or else manually run the rc.local script:
1 | sudo /etc/rc.local |
If you don’t use an rTorrent front end, or want to view rTorrent in a terminal for whatever reason, you can reattach it to your terminal with the following command:
1 | dtach -a /tmp/rtorrent.dtach |
You can either press ctrl+z or simply close the terminal to quit dtach (rTorrent will keep running in the background).
Thanks it is working great !
Thanks for the howto! It works fine apart from the problem that when you reattaches the arrow keys don’t work (http://libtorrent.rakshasa.no/ticket/192).
The solution for this is setting env TERM=linux.
I tried inserting this in the start-stop-daemon command but I can’t get it working. Any advice?
Also if you shutdown or reboot next time you start it has to hashcheck all the torrents, to prevent this add ‘kill -2 $(pgrep rtorrent)’ to the /etc/rc0.d and /etc/rc6.d .