Pages - Menu

Saturday, April 21, 2012

starting rtorrent on system startup

rTorrent is a curses-based bittorrent client for Linux.

It's very light on system resources but has great features such as monitoring of a directory for .torrent files, auto-move based on status (incoming, seeding, complete, etc), categories, magnet link handling and RSS capabilities.

I have a headless system where I seed some (legal) torrents and wanted rTorrent to start up when the system did. There are some examples of init scripts on the rTorrent site but I didn't like how these ran, specifically the su constantly needing a password and the odd way it started GNU Screen.

Download
Installation
  • Put it at /etc/init.d/bittorrent and make it executable
    chmod +x /etc/init.d/bittorrent
  • Add to chkconfig
    chkconfig --add bittorrent
  • Set to start on system startup
    chkconfig bittorrent on
  • If you want non-root users to be able to control it, put this in your visudo, replace "username" with your non-priveledged username
    username localhost=NOPASSWD:/etc/init.d/bittorrent*
  • Setup an alias to the script in the user's ~/.bashrc
    alias bittorrent='/etc/init.d/bittorrent'
    alias bt='bittorrent'
Requirements
  • CentOS 6 or Fedora 12-14. Probably also works on CentOS 5.
  • screen and rtorrent
  • A non-priveledged user to run rtorrent, this can either be a new user just to run torrents, or an existing user
  • Absolute session path in the .rtorrent.rc file
    session = /home/rtorrent/.session  ## this is good
    session = ~/.session               ## this will break
    session = .session                 ## so will this
  • Paths for other actions such as monitoring directories for .torrent files and auto-moving complete downloads don't have to be absolute.
Usage
  • Control the daemon withbittorrent start, bittorent stop, bittorrent restart
  • Get information about the daemon with
    bittorrent status, bittorrent info
  • Connect to the screen session with
    bittorrent connect
    (press ctrl+a then d to disconnect)
Licensing

2 comments:

Anonymous said...

Very good script and really thank you for it.
Two small problems I found so far.
1. Line 34, in my distribution there was no such file, so I just disabled it.
2. Line 149 was giving errors so I changed it to:
if [[ -n $(ps -fe | grep ${PID}|grep ${SERVICE}) ]];

I hope this will be helpful for someone else too.

Anonymous said...

Another "improvement", for me sometimes during shutdown rtorrent was not stopped, and this leaving the lock file. So originally the script was checking if there is lock file and if yes, not starting, I added check for process too, so if lock file exists but no rtorrent process, it will start.

so i little modified it(adding get_pid, and extending the check):
get_pid;
if ! [ -s ${SESSIONPATH}/rtorrent.lock ] || ! [[ -n $(ps -fe | grep ${PID}|grep ${SERVICE}) ]];