You are not logged in.
Pages: 1
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 0
Copy 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 06: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
It's so nice! Great job! Thanks
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 0
I 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
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?
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 0
It's configurable by /etc/conf.d/rtorrent. I hope somebody will find this little script helpful.
It's not the best thing when they call you a "member" you know…
Offline
EDIT: Got it working somehow, so np!
Sorry to bump it all up, but i'm encountering a problem.
Right after i boot the daemon up, it instantly fails on me. Any idea why? This is the script:
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
case "$1" in
start)
stat_busy "Starting rtorrent"
su median -c 'screen -d -m -S rtorrent rtorrent' &> /dev/null
if [ $? -gt 0 ]; then
stat_fail
else
add_daemon rtorrent
stat_done
fi
;;
stop)
stat_busy "Stopping rtorrent"
killall -w -s 2 /usr/bin/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 0
Last edited by Median (2011-06-16 23:07:21)
Offline
Though i managed to encounter another problem, it starts up fine at boot, or at least it says done, but when i log in on my user (median) there's no screen available for rtorrent and i need to start the daemon manually.. Any idea?
Offline
I think you should start a new thread.
Do you have screen installed?
Offline
I do, and i guess i will.
Offline
Pages: 1