Advertisement
ryzhov_al

[WD My Book Live] Rtorrent start script

Jan 28th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.22 KB | None | 0 0
  1. ryzhovau@MBL:~$ cat /etc/init.d/rtorrent
  2. #!/bin/bash
  3. ### BEGIN INIT INFO
  4. # Provides:          rtorrent
  5. # Required-Start:    $local_fs $remote_fs $network $syslog
  6. # Required-Stop:     $local_fs $remote_fs $network $syslog
  7. # Default-Start:     2 3 4 5
  8. # Default-Stop:      0 1 6
  9. # Short-Description: Start/stop rtorrent daemon
  10. ### END INIT INFO
  11.  
  12. # ------------------------------------------------------------------------------
  13. # /etc/init.d/rtorrent
  14. #
  15. # This script is an init script to run rtorrent in the background, using a
  16. # screen. The script was designed and tested for Debian systems, but may work on
  17. # other systems. On Debian, enable it by moving the script to
  18. # "/etc/init.d/rtorrent" and issuing the command
  19. # "update-rc.d rtorrent defaults 99"
  20. #    ____                _ _
  21. #   / ___|  ___  ___  __| | |__   _____  __
  22. #   \___ \ / _ \/ _ \/ _` | '_ \ / _ \ \/ /
  23. #    ___) |  __/  __/ (_| | |_) | (_) >  <
  24. #   |____/ \___|\___|\__,_|_.__/ \___/_/\_\
  25. #
  26. # @see http://methvin.net/scripts/rtorrent
  27. # @see http://tldp.org/LDP/abs/html/
  28. # ------------------------------------------------------------------------------
  29.  
  30. ## Username to run rtorrent under, make sure you have a .rtorrent.rc in the
  31. ## home directory of this user!
  32. USER="www-data"
  33.  
  34. ## Absolute path to the rtorrent binary.
  35. RTORRENT="/usr/local/bin/rtorrent"
  36.  
  37. ## Absolute path to the screen binary.
  38. SCREEN="/usr/bin/screen"
  39.  
  40. ## Name of the screen session, you can then "screen -r rtorrent" to get it back
  41. ## to the forground and work with it on your shell.
  42. SCREEN_NAME="rtorrent"
  43.  
  44. ## Absolute path to rtorrent's PID file.
  45. PIDFILE="/var/run/rtorrent.pid"
  46.  
  47. ## Absolute path to rtorrent's XMLRPC socket.
  48. SOCKET="/var/lib/rtorrent/rpc.socket"
  49.  
  50. ## Check if the socket exists and if it exists delete it.
  51. delete_socket() {
  52.     if [[ -e $SOCKET ]]; then
  53.         rm -f $SOCKET
  54.     fi
  55. }
  56.  
  57. set_socket_perm() {
  58.     i=0
  59.     while [ $i -le 10 ]
  60.     do
  61.     if [[ -e $SOCKET ]]; then
  62.         chmod 777 $SOCKET
  63.         break
  64.     fi
  65.     sleep 1
  66.     i=`expr $i + 1`
  67.   done
  68. }
  69.  
  70. case "$1" in
  71.     ## Start rtorrent in the background.
  72.     start)
  73.         echo "Starting rtorrent."
  74.         delete_socket
  75.         start-stop-daemon --start --background --oknodo \
  76.             --pidfile "$PIDFILE" --make-pidfile \
  77.             --chuid $USER \
  78.             --exec $SCREEN -- -DmUS $SCREEN_NAME $RTORRENT -n -o import=/mnt/DataVolume/home/lighttpd/.rtorrent.rc
  79.         if [[ $? -ne 0 ]]; then
  80.             echo "Error: rtorrent failed to start."
  81.             exit 1
  82.         fi
  83.         set_socket_perm
  84.         echo "rtorrent started successfully."
  85.         ;;
  86.  
  87.     ## Stop rtorrent.
  88.     stop)
  89.         echo "Stopping rtorrent."
  90.         start-stop-daemon --stop --oknodo --pidfile "$PIDFILE"
  91.         if [[ $? -ne 0 ]]; then
  92.             echo "Error: failed to stop rtorrent process."
  93.             exit 1
  94.         fi
  95.         delete_socket
  96.         echo "rtorrent stopped successfully."
  97.         ;;
  98.  
  99.     ## Restart rtorrent.
  100.     restart)
  101.         "$0" stop
  102.         sleep 1
  103.         "$0" start || exit 1
  104.         ;;
  105.  
  106.     ## Print usage information if the user gives an invalid option.
  107.     *)
  108.         echo "Usage: $0 [start|stop|restart]"
  109.         exit 1
  110.         ;;
  111.  
  112. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement