#!/bin/sh # # Check http://wiki.debian.org/LSBInitScripts # ### BEGIN INIT INFO # Provides: torrent # Required-Start: $local_fs $network $syslog # Required-Stop: $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start torrent in a screen session ### END INIT INFO start_transmission() { # run screen as root, otherwise rtorrent would own a screen process # it cannot access to, due to /dev/pts/* acls. screen -dmS torrent su --login torrent -c "transmission-daemon -f" } configure_transmission() { su --login torrent -c "transmission-remote --folder /server/torrent/download/ --port-mapping --encryption preferred --download-unlimited --upload-limit 5 --enable-pex" } stop_transmission() { su --login torrent -c "transmission-remote -q" } stop_screen() { screen -X "exit" torrent } case "$1" in start) echo "Starting torrent..." stop_screen > /dev/null # we shouldn't have concurrent screen sessions start_transmission sleep 5s && configure_transmission & # time for the daemon to start ;; stop) echo "Stopping torrent..." stop_transmission stop_screen ;; restart) echo "Restarting torrent..." stop_transmission stop_screen start_transmission sleep 5s && configure_transmission & # time for the daemon to start ;; force-reload) echo "Reloading torrent..." configure_transmission ;; status) # quite crude ps aux | grep transmission ;; *) echo "Usage: $0 {start|stop|restart|force-reload|status}" exit 1 ;; esac exit 0