[root@localhost ~]# egrep -v \#\|^$ /etc/init.d/rtorrent user="albatross" HOME="/home/albatross" config="`su -c 'echo $HOME' $user`/.rtorrent.rc" echo $config options="" base="`su -c 'echo $HOME' $user`" srnname="rtorrent" logfile="/var/log/rtorrentInit.log" PATH=/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin DESC="rtorrent" NAME=rtorrent DAEMON=$NAME SCRIPTNAME=/etc/init.d/$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 rtorrent binary in PATH $PATH" | tee -a "$logfile" >&2 exit 3 fi if ! [ -r "${config}" ] ; then echo "cannot find readable config ${config}. check that it is there and permissions are appropriate" | tee -a "$logfile" >&2 exit 3 fi session=`getsession "$config"` if ! [ -d "${session}" ] ; then echo "cannot find readable session directory ${session} from config ${co nfig}. check permissions" | tee -a "$logfile" >&2 exit 3 fi } d_start() { [ -d "${base}" ] && cd "${base}" stty stop undef && stty start undef su -c "screen -ls | grep -sq "\.${srnname}[[:space:]]" " ${user} || su -c "scr een -dm -S ${srnname} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2 su -c "screen -S "${srnname}" -X screen rtorrent ${options} 2>&1 1>/dev/null" ${user} | tee -a "$logfile" >&2 } d_stop() { session=`getsession "$config"` if ! [ -s ${session}/rtorrent.lock ] ; then return fi pid=`cat ${session}/rtorrent.lock | awk -F: '{print($2)}' | sed "s/[^0-9]//g "` kill -s INT ${pid} fi } getsession() { session=`cat "$1" | grep "^[[:space:]]*session[[:space:]]*=" | sed "s/^[[:sp ace:]]*session[[:space:]]*=[[:space:]]*//" ` echo $session } checkcnfg case "$1" in start) echo -n "Starting $DESC: $NAME" d_start echo "." ;; stop) echo -n "Stopping $DESC: $NAME" d_stop echo "." ;; restart|force-reload) echo -n "Restarting $DESC: $NAME" d_stop sleep 1 d_start echo "." ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 [root@localhost ~]#