# #!/bin/bash # # # A simple RTorrent initscript for debian-based distros # # Distributed as-is, no warranties # # Comments, ideas etc - mail me - ivan4groznij [at] gmail [dot] com # # Based upon http://mehulved.wordpress.com/2008/07/16/start-rtorrent-using-init-scripts/ # # Requires GNU Screen # # This script does not perform any checks, i.e. wether the user exists, is screen installed etc # # # The user to run rtorrent as # RTUSER=dean # # # Paths to different binaries # RTORRENT=/usr/bin/rtorrent # KILL=/bin/kill # SCREEN=/usr/bin/screen # # # PIDfile path # PIDFILE=/var/run/rtorrent.pid # # start_rt() # { # echo -n "Starting rtorrent... " # start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --chuid $RTUSER --exec $SCREEN -- -DmUS torrent $RTORRENT # if [ $? -eq 0 ]; then # echo "success!" # echo "To interact with the torrent client, you will need to reattach the screen session with following command:" # echo " screen -r torrent" # else # echo "fail!" # fi # } # # stop_rt() # { # echo -n "Stopping rtorrent... " # start-stop-daemon --stop --pidfile $PIDFILE # if [ $? -eq 0 ]; then # echo "The process stopped successfully" # else # echo "The process failed to stop" # fi # } # # status_rt() # { # echo -n "Status: " # PID=`cat $PIDFILE` # # # Check if the process with the specified PID exists # # kill -0 will return 0 if the process exists # $KILL -0 $PID # if [ $? -eq 0 ]; then # echo "started" # return 0 # else # echo "stopped" # return 1 # fi # # } # # restart_rt_if_needeed() # { # # Seems like Rtorrent sometimes crashes. This function # # restarts rtorrent if it's not running # status_rt # if [ $? -ne 0 ]; then # echo "Rtorrent is not running. Restart needed" # stop_rt # start_rt # else # echo "Restart is not needed" # fi # } # # case "$1" in # start) # start_rt # ;; # stop) # stop_rt # ;; # restart) # stop_rt # start_rt # ;; # restart_if_needed) # restart_rt_if_needeed # ;; # status) # status_rt # ;; # *) # echo "Usage: {start|stop|restart|status|restart_if_needed}" # ;; # esac