Created
April 14, 2013 14:31
-
-
Save kramer/5382951 to your computer and use it in GitHub Desktop.
chkconfig compatible rtorrent script. put in "/etc/init.d/rtorrent", then do "chkconfig --add rtorrent" and "chkconfig --level 3 rtorrent on". Originally from: "http://petrich.me/files/scripts/rtorrent"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# rtorrent Startup script for rTorrent | |
# | |
# chkconfig: - 90 15 | |
# description: rTorrent is the console torrent client | |
# config: /home/rtorrent/.rc. | |
# Source Red Hat function library. | |
. /etc/rc.d/init.d/functions | |
RETVAL=0 | |
PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin | |
NAME=rtorrent | |
USER="root" | |
CONFIG=("$(su -c 'echo $HOME' $USER)/.rtorrent.rc") | |
LOG_FILE=/var/log/$NAME.log | |
LOCK_FILE=/var/lock/subsys/$NAME | |
checkcnfg() { | |
exists=0 | |
for i in `echo "$PATH" | tr ':' '\n'` ; do | |
if [ -f $i/$NAME ] ; then | |
exists=1 | |
break | |
fi | |
done | |
if [ $exists -eq 0 ] ; then | |
echo "cannot find $NAME binary in PATH: $PATH" | tee -a "$LOG_FILE" >&2 | |
exit 3 | |
fi | |
for (( i=0 ; i < ${#CONFIG[@]} ; i++ )) ; do | |
if ! [ -r "${CONFIG[i]}" ] ; then | |
echo "cannot find readable config ${CONFIG[i]}. check that it is there and permissions are appropriate" | tee -a "$LOG_FILE" >&2 | |
exit 3 | |
fi | |
session=$(getsession "${CONFIG[i]}") | |
if ! [ -d "${session}" ] ; then | |
echo "cannot find readable session directory ${session} from config ${CONFIG[i]}. check permissions" | tee -a "$LOG_FILE" >&2 | |
exit 3 | |
fi | |
done | |
} | |
checkscreen () { | |
if [ ! -f /usr/bin/screen ] ; then | |
echo "\"screen\" program is not installed! Please install it. You can do it if run \"\# yum install screen\"" | |
exit 3 | |
fi | |
} | |
start() { | |
echo -n $"Starting $NAME: " | |
checkcnfg || checkscreen || exit 1 | |
daemon "su $USER -c 'screen -d -m rtorrent'" | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && touch $LOCK_FILE | |
return $RETVAL | |
} | |
stop() { | |
echo -n $"Stopping $NAME: " | |
killproc rtorrent | |
su $USER -c 'screen -wipe' >/dev/null 2>&1 | |
RETVAL=$? | |
echo | |
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE | |
} | |
getsession() { | |
session=$(cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed "s/^[[:space:]]*session[[:space:]]*=[[:space:]]*//" ) | |
#session=${session/#~/`getent passwd ${user}|cut -d: -f6`} | |
echo $session | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
*) | |
echo $"Usage: $NAME {start|stop|restart}" >&2 | |
exit 1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment