This blog is about Java (advanced Java topics like Reflection, Byte Code transformation, Code Generation), Maven, Web technologies, Raspberry Pi and IT in general.

Dienstag, 14. Mai 2013

Tutorial: How to automatically start opentracker and rtorrent on a Raspberry Pi


Motivation

In my last post I explained how to setup a torrent-box on a Raspberry Pi. But there is still one important thing to do: automatically start opentracker and rtorrent so you needn't to do it yourself after each reboot. It's not that easy because rtorrent can't be started as deamon and you probably want to be able to get the background rtorrent process so you can change the setting (e.g. limit the upload speed). To solve this problem I used tmux.

Setup the autostart


The first thing is to put the opentracker executable into the /usr/bin
Then install tmux

sudo apt-get install tmux

Now we have to write our init.d script which will be called at the startup

sudo nano /etc/init.d/torrent

With this content

# !/bin/sh
# /etc/init.d/torrent

BIN="/usr/bin"

case "$1" in
  start)
    echo "Starting torrent"
    start-stop-daemon --start --background --chuid=pi --exec $BIN/opentracker
    start-stop-daemon --start --background --chuid=pi --exec $BIN/tmux -- new-session -d -n rtorrent -s rtorrent rtorrent
    ;;
  stop)
    echo "Stopping torrent"
    killall opentracker
    killall rtorrent
    ;;
  *)
    echo "Usage: /etc/init.d/torrent {start|stop}:"
    exit 1
    ;;
esac

exit 0

Make the file executable and embed it into the starting process

sudo chmod 755 /etc/init.d/torrent.sh
sudo update-rc.d torrent.sh defaults

Basically that's it.

tmux

To get your running rtorrent process write

tmux attach

To put it back into the background press ctrl+b and then press d (for deattch).

tmux cheat cheet.

1 Kommentar:

  1. Thx! This is exactly what I was looking for. Don't forget to exchange pi with your username!

    AntwortenLöschen