Ubuntu – RTorrent init script not working

init.drtorrentrutorrentusers

I'm trying to set up an Ubuntu 14.04 box with rTorrent and ruTorrent. I've installed rTorrent and it launches just fine using my own user account.

I've created a new user account named rtorrent to run rTorrent.

sudo adduser --system --group rtorrent

Next I set up the config file .rtorrent.rc in /home/rtorrent and made rtorrent the owner of said file.

sudo chown rtorrent:rtorrent .rtorrent.rc

I would very much like for rtorrent to automatically start. I borrowed the below init script from this guide:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          rtorrent
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start/stop rtorrent daemon
### END INIT INFO

## Username to run rtorrent under, make sure you have a .rtorrent.rc in the
## home directory of this user!
USER="rtorrent"

## Absolute path to the rtorrent binary.
## run "which rtorrent"
RTORRENT="/usr/local/bin/rtorrent"

## Absolute path to the screen binary.
SCREEN="/usr/bin/screen"

## Name of the screen session, you can then "screen -r rtorrent" to get it back
## to the foreground and work with it on your shell.
SCREEN_NAME="rtorrent"

## Absolute path to rtorrent's PID file.
PIDFILE="/var/run/rtorrent.pid"

## Absolute path to rtorrent's XMLRPC socket.
SOCKET="/var/run/rtorrent/rpc.socket"

## Check if the socket exists and if it exists delete it.
delete_socket() {
if [[ -e $SOCKET ]]; then
rm -f $SOCKET
fi
}

case "$1" in
## Start rtorrent in the background.
start)
echo "Starting rtorrent."
delete_socket
start-stop-daemon --start --background --oknodo \
--pidfile "$PIDFILE" --make-pidfile \
--chuid $USER \
--exec $SCREEN -- -DmUS $SCREEN_NAME $RTORRENT
if [[ $? -ne 0 ]]; then
echo "Error: rtorrent failed to start."
exit 1
fi
echo "rtorrent started successfully."
;;

## Stop rtorrent.
stop)
echo "Stopping rtorrent."
start-stop-daemon --stop --oknodo --pidfile "$PIDFILE"
if [[ $? -ne 0 ]]; then
echo "Error: failed to stop rtorrent process."
exit 1
fi
delete_socket
echo "rtorrent stopped successfully."
;;

## Restart rtorrent.
restart)
"$0" stop
sleep 1
"$0" start || exit 1
;;

## Print usage information if the user gives an invalid option.
*)
echo "Usage: $0 [start|stop|restart]"
exit 1
;;

esac

Next:

sudo chmod +x /etc/init.d/rtorrent
sudo update-rc.d rtorrent defaults 99

Sadly, after a reboot and doing

sudo top

rtorrent is nowhere to be seen. When I do

sudo /etc/init.d/rtorrent start

I receive the message that rtorrent has started, but I still can't find it when running top.

How can I get it to work?

Best Answer

Shortly after posting this question it dawned on me. My .rtorrent.rc file was not the same for both users. After fixing the config for the user rtorrent everything works.

Related Question