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

  • rtorrent
  • screen
  • adequate knowledge to operate rtorrent and screen

Steps to get started

  • Copy the contents of the script for your distro to a file
  • Save it with the name indicated in the script
  • Make the file executable with following command

chmod +x /path/to/file

  • Add it to your default boot level as indicated in the comments
  • Change the TUSER value from username to your username
  • 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.

Advertisements

Patching xorg-server-1.4.0.90 to work on gentoo/freebsd

While compiling xorg-server on gentoo/freebsd, I was getting an error. So, I paid a visit to #gentoo-bsd on irc.freenode.net. WIth the help of friendly people out there I found that it’s missing something but seemed to be out of luck as we couldn’t find out what was missing.

A quickfire query at bugs.gentoo.org revealed that there was indeed a bug filed with xorg-server-1.4.0. You can find the bug at http://bugs.gentoo.org/show_bug.cgi?id=205149
So, basically I needed to patch up my xorg-server files with the 2 patches given out there. Continue reading