top of page

MEHUL'S SPACE

Start rtorrent using init scripts

Searching around the net I came across 2 articles which helped in writing the init script presented below. There are 3 versions of the script – one for gentoo based distros one for debian based distros and one for Fedora, which is quite similar to debian one. Requirements for running the scripts

  1. rtorrent

  2. screen

  3. adequate knowledge to operate rtorrent and screen

Steps to get started

  1. Copy the contents of the script for your distro to a file

  2. Save it with the name indicated in the script

  3. Make the file executable with following command

chmod +x /path/to/file
  1. Add it to your default boot level as indicated in the comments

  2. Change the TUSER value from username to your username

  3. Optionally you can change rtorrent to some other bittorrent client depending on your preference. NOTE:- It should be a CLI bittorrent client

The gentoo version of the script

#!/sbin/runscript # To add the script automatically at the startup execute the following command in the terminal # eselect rc add rtorrent default RTUSER=username TORRENT=/usr/bin/rtorrent opts=”start stop” depend() { #this daemon needs internet to function need net.eth0 use logger } start() { #display to user that what is being started ebegin “Starting rtorrent” #start the process and record record it’s pid start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER # To interact with rtorrent you will need to reattach the screen einfo “To use your rtorrent session, reattach screen using following command:” einfo “screen -r torrent” #output failure or success if [[ $? -eq 0 ]]; then if [[ $? -eq 0 ]]; then eend “Process started successfully” else eend “Process failed to start” } stop () { #display that we are stopping the process ebegin “Stopping rtorrent” #stop the process using pid from start() start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent #output success or failure if [[ $? -eq 0 ]]; then eend “Process stopped successfully” else eend “Process failed to stop” }

Debian version

#!/bin/bash # To start the script automatically at bootup type the following command # update-rc.d torrent defaults 99 RTUSER=username TORRENT=/usr/bin/rtorrent case $1 in start) #display to user that what is being started echo “Starting rtorrent” #start the process and record record it’s pid start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER #output failure or success #info on how to interact with the torrent echo “To interact with the torrent client, you will need to reattach the screen session with following command” echo “screen -r torrent” if [[ $? -eq 0 ]]; then echo “The process started successfully” else echo “The process failed to start” ;; stop) #display that we are stopping the process echo “Stopping rtorrent” #stop the process using pid from start() start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent #output success or failure if [[ $? -eq 0 ]]; then echo “The process stopped successfully” else echo “The process failed to stop” ;; *) # show the options echo “Usage: {start|stop}” ;; esac

Seems that debian version will work for Fedora too. Still, here’s the script

#!/bin/bash # To start the script automatically at bootup type the following command # chkconfig add torrent RTUSER=username TORRENT=/usr/bin/rtorrent case $1 in start) #display to user that what is being started echo “Starting rtorrent” #start the process and record record it’s pid start-stop-daemon –start –background –pidfile /var/run/rtorrent.pid –make-pidfile –exec su -c “/usr/bin/screen -dmUS torrent $TORRENT” $RTUSER #output failure or success #info on how to interact with the torrent echo “To interact with the torrent client, you will need to reattach the screen session with following command” echo “screen -r torrent” if [[ $? -eq 0 ]]; then echo “The process started successfully” else echo “The process failed to start” ;; stop) #display that we are stopping the process echo “Stopping rtorrent” #stop the process using pid from start() start-stop-daemon –stop –pidfile /var/run/rtorrent.pid –name rtorrent #output success or failure if [[ $? -eq 0 ]]; then echo “The process stopped successfully” else echo “The process failed to stop” ;; *) # show the options echo “Usage: {start|stop}” ;; esac

One thing I need to implement is to show status. If it is started or stopped. Reload or restart doesn’t seem to make much sense to me thus I haven’t implemented those. This is only the initial version it may have bugs. Please report them so they can be corrected. Debian and fedora users please try it and report if it works. For user of other distros, if interested, please provide some idea of your distro’s init system or attach some init script so that I can work on it. For people familiar with init system, it would be great to post your modifications/improvements/bug fixes/ideas to this script.

2 views0 comments

Recent Posts

See All

Mediawiki on dotcloud

Unfortunately, there’s no guide available for installing mediawiki on dotcloud and googling for it doesn’t turn up anything much useful. But, I had to move out LUG wiki to dotcloud. I proceeded with i

WordPress Performance Tips

Do you find performance of your WordPress blog to be lousy? And have no clue on where to start with it? There are lots of articles on the Internet which will tell you what to do. So, instead of repeat

BarCampMumbai5 – The Experience, The Firsts

Sunday February 1 2009 was the day when BarCampMumbai 5 was held with the same old enthusiasm but at a whole new venue – VJTI College, Matunga. The camp was host to many firsts for the BCM as well as

Comments


bottom of page