Skip to content

Instantly share code, notes, and snippets.

@Blacksly
Created June 14, 2014 10:36
Show Gist options
  • Save Blacksly/73fc9c6488b993e6c5ca to your computer and use it in GitHub Desktop.
Save Blacksly/73fc9c6488b993e6c5ca to your computer and use it in GitHub Desktop.
#!/bin/sh -e
# Start/Stop rtorrent sous forme de daemon.
NAME=rtorrent-daemon.sh
SCRIPTNAME=/etc/init.d/$NAME
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
case $1 in
start)
echo "Starting rtorrent... "
su -l USER -c "screen -fn -dmS rtd nice -19 rtorrent"
echo "Terminated"
;;
stop)
if [ "$(ps aux | grep -e '.*rtorrent$' -c)" != 0 ]; then
{
echo "Shutting down rtorrent... "
killall -r "^.*rtorrent$"
echo "Terminated"
}
else
{
echo "rtorrent not yet started !"
echo "Terminated"
}
fi
;;
restart)
if [ "$(ps aux | grep -e '.*rtorrent$' -c)" != 0 ]; then
{
echo "Shutting down rtorrent... "
killall -r "^.*rtorrent$"
echo "Starting rtorrent... "
su -l USER -c "screen -fn -dmS rtd nice -19 rtorrent"
echo "Terminated"
}
else
{
echo "rtorrent not yet started !"
echo "Starting rtorrent... "
su -l USER -c "screen -fn -dmS rtd nice -19 rtorrent"
echo "Terminated"
}
fi
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment