#!/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 # This script is an init script to run rtorrent in the background, # using a screen. The script was designed and tested for Debian # systems, but may work on other systems. On Debian, enable it by # moving the script to "/etc/init.d/rtorrent" and issuing the command # "update-rc.d rtorrent defaults 99" USER=greg # username to run rtorrent under RTORRENT=/usr/bin/rtorrent # rtorrent binary SCREEN=/usr/bin/screen # screen binary SCREEN_NAME=rtorrent # screen name (this way you can screen -r rtorrent) PIDFILE=/var/run/rtorrent.pid # pidfile case "$1" in start) echo "Starting rtorrent." 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) echo "Stopping rtorrent." start-stop-daemon --stop --oknodo --pidfile "$PIDFILE" if [[ $? -ne 0 ]]; then echo "Error: failed to stop rtorrent process." exit 1 fi echo "rtorrent stopped successfully." ;; restart|force-reload) "$0" stop sleep 1 "$0" start || exit 1 ;; *) echo "Usage: $0 [start|stop|restart]" exit 1 ;; esac