Bash & Python‎ > ‎

A new improved rtorrent service script

posted Nov 14, 2012, 11:51 AM by Peter G. Marczis
I had already one init.d script for rtorrent which was using screen ( here ).
Well, almost a year ago, I "discovered" tmux, as a good alternative for screen. In fact I found that tmux is a little be more stable, and have some extra fancy feature. Of course you have to have a good rc file to get much out of it. 

Read more about tmux here:

So, the new "improved" init.d script:

#!/bin/bash 
### BEGIN INIT INFO
# Provides:          rtorrent
# Required-Start:    
# X-Start-Before:    
# Required-Stop:
# Default-Start:     2 
# Default-Stop:      1
# Short-Description: run rtorrent as a given user in a tmux. 
# Description:       run rtorrent as a given user in a tmux.
### END INIT INFO

#Setup
#The user who will run the client. This user must have an rtorrentrc in her home dir.
USER=username
#You don't really have to change these...
SESS_NAME=rtorrent

case "$1" in
start)
sudo -u $USER tmux new-session -d -s rtorrent $SESS_NAME
if [ $? -ne 0 ] ; then
echo "RTorrent is running."
else
echo "RTorrent is started."
fi
;;

stop)
PID=$(pidof rtorrent)
if [ "$PID" != "" ] ; then
kill $PID
echo "RTorrent now stopped."
else
echo "RTorrent is NOT running."
fi
;;

bring-front)
if [ -e $PIDFILE ] ; then
sudo -u $USER tmux at -t $SESS_NAME
fi
;;

*)
echo "Usage: $0 start|stop|bring-front"
;;
esac

If you don't know how to use it, you should not use it. 
Some hints (for ubuntu / debian users, others please refer to http://bit.ly/THMNaH):

  1. Copy this into /etc/init.d named as you like ( preferably rtorrent )
  2. run:  sudo update-rc.d <your chosen name from #1> defaults
  3. run: sudo service rtorrent start
I hope it helps for you too, to share Linux images over torrent.

Comments