Table of Contents

About

Starts a multiplexed instance of rtorrent in the background. The configurable parameters are:

DAEMON=/usr/bin/rtorrent
DAEMON_USER=torrent

Accessing rTorrent

Depending on the rTorrent user set with DAEMON_USER in the code section, you can attach to the rtorrent multiplexed session by issuing:

su torrent
tmux attach-session -t rtorrent

where torrent is configured via DAEMON_USER.

To suspend the session, use the key combo Ctrl+B and then press D.

Code

#! /bin/sh
### BEGIN INIT INFO
# Provides:          rtorrent
# Required-Start:    $local_fs $remote_fs $network $syslog $named $openvpn
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:	     0 1 6
# Short-Description: Start rtorrent.
# Description:       Starts the rtorrent daemon.
### END INIT INFO
 
###########################################################################
##  Copyright (C) Wizardry and Steamworks 2013 - License: GNU GPLv3      ##
##  Please see: http://www.gnu.org/licenses/gpl.html for legal details,  ##
##  rights of fair usage, the disclaimer and warranty conditions.        ##
###########################################################################
 
PATH=/sbin:/usr/bin
DAEMON=/usr/bin/rtorrent
DAEMON_USER=torrent
TMUX=/usr/bin/tmux
 
# Get lsb functions
. /lib/lsb/init-functions
 
do_start () {
	log_begin_msg "Starting rtorrent daemon..."
	HOMEDIR=`getent passwd $DAEMON_USER | cut -d: -f6`
	if [ -x $DAEMON ]; then
		HOME="$HOMEDIR" start-stop-daemon --start -c $DAEMON_USER --pidfile $HOMEDIR/rtorrent.pid --make-pidfile --background --exec $TMUX -d $HOMEDIR -- new-session -d -n rtorrent -s rtorrent $DAEMON 
	fi
	log_end_msg $?
}
do_stop () {
	log_begin_msg "Stopping rtorrent daemon..."
	HOMEDIR=`getent passwd $DAEMON_USER | cut -d: -f6`
	if [ -x $DAEMON ]; then
		start-stop-daemon -o -c $DAEMON_USER -K -u $DAEMON_USER -x $DAEMON
	fi
	log_end_msg $?
}
 
status () {
	status_of_proc "$DAEMON" rtorrent
}
 
case "$1" in
  start)
	do_start
	;;
  restart)
  	do_stop
  	/bin/sleep 1
  	do_start
  	;;
  status)
  	status
  	;;
  stop)
	do_stop
	;;
  *)
	echo "Usage: rtorrent [start|stop|restart|status]" >&2
	exit 3
	;;
esac
 
exit 0