Discussion forums for Arch Linux, a simple, lightweight linux distribution.
You are not logged in.
Some time ago I wrote an initscript for Gentoo to run rtorrent as a daemon (using dtach). Since I recently made the switch from Gentoo to Arch I sort of translated this script to the Arch style. Here's the result:
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
case "$1" in
start)
stat_busy "Starting rtorrent"
su - USER -c 'dtach -n /tmp/rtorrent.dtach /usr/bin/rtorrent' &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon rtorrent
stat_done
fi
;;
stop)
stat_busy "Stopping rtorrent"
killall -s 2 rtorrent &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon rtorrent
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0Copy this into /etc/rc.d/rtorrent and add the daemon to /etc/rc.conf. Make sure you change USER in the script above to your user name! For further instructions refer to my post on the Gentoo forums.
Cheers!
Last edited by roog (2008-08-13 02:55:44)
Offline
Awesome, it works great.
Thanks!
Offline
Thanks, i use it for hellanzb now, maybe you can make a wiki page for this!
Offline
Oh . . . nice.
Offline
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
case "$1" in
start)
stat_busy "Starting rtorrent"
su - rtorrent -c 'screen -R rtorrent rtorrent' &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon rtorrent
stat_done
fi
;;
stop)
stat_busy "Stopping rtorrent"
killall -s 2 rtorrent &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon rtorrent
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0I modified your daemon to use screen. But I ran into an error. I created the 'rtorrent' user but when I run the daemon it FAILS right away (no messages just the [FAIL] indicator.) Any ideas?
Offline
i think what you want is
su - rtorrent -c 'screen -d -m rtorrent' &> /dev/null ## -d -m will start screen in "detached" mode, meaning that it will put the session in background right away
additionally, a question to the original poster. what is the - switch good for with su? i know it means "create a login shell" but what are the advantages of that?
Offline
Heller_Barde wrote:
i think what you want is
Code:
su - rtorrent -c 'screen -d -m rtorrent' &> /dev/null ## -d -m will start screen in "detached" mode, meaning that it will put the session in background right awayadditionally, a question to the original poster. what is the - switch good for with su? i know it means "create a login shell" but what are the advantages of that?
Thanks!
Offline
Very nice!
I've made a similar script myself based on examples on rtorrent wiki. Here it is:
/etc/rc.d/rtorrent
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
[ -f /etc/conf.d/rtorrent ] && . /etc/conf.d/rtorrent
[ -z "$RTORRENT" ] && RTORRENT=/usr/bin/rtorrent
[ -z "$RTORRENT_USER" ] && RTORRENT_USER=rtorrent
[ -z "$RTORRENT_HOME" ] && RTORRENT_HOME=/home/rtorrent
[ -z "$RTORRENT_SOCKET" ] && RTORRENT_SOCKET=$RTORRENT_HOME/.socket
[ -z "$RTORRENT_LOCK" ] && RTORRENT_LOCK=$RTORRENT_HOME/session/rtorrent.lock
[ -z "$RTORRENT_DTACH" ] && RTORRENT_DTACH="/usr/bin/dtach -n $RTORRENT_SOCKET -z"
case "$1" in
start)
stat_busy "Starting rtorrent"
PID=`pidof -o %PPID $RTORRENT`
if [ -z "$PID" ]; then
[ -S $RTORRENT_SOCKET ] && rm $RTORRENT_SOCKET &> /dev/null
[ -f $RTORRENT_LOCK ] && rm $RTORRENT_LOCK &> /dev/null
fi
/bin/su -c "$RTORRENT_DTACH $RTORRENT &> /dev/null" \
$RTORRENT_USER
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon rtorrent
stat_done
fi
;;
stop)
stat_busy "Stopping rtorrent"
PID=`pidof -o %PPID $RTORRENT`
[ ! -z "$PID" ] && kill -s INT $PID &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
rm_daemon rtorrent
stat_done
fi
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
echo "usage: $0 {start|stop|restart}"
esac
exit 0It's configurable by /etc/conf.d/rtorrent. I hope somebody will find this little script helpful.
Offline