Skip to content

Instantly share code, notes, and snippets.

@tiagoad
Created August 8, 2014 14:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagoad/feac3c880694a696f540 to your computer and use it in GitHub Desktop.
Save tiagoad/feac3c880694a696f540 to your computer and use it in GitHub Desktop.
rtorrent init file
#!/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=rtorrent # 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment