You are not logged in.

#1 2008-08-13 06:50:00

roog
Member
Registered: 2008-08-12
Posts: 7

rtorrent daemon

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

#2 2008-08-13 16:28:26

BetterLeftUnsaid
Member
From: My Happy Place
Registered: 2007-11-04
Posts: 78

Re: rtorrent daemon

Awesome, it works great.

Thanks!

Offline

#3 2008-08-14 11:05:41

Vintendo
Member
From: Netherlands
Registered: 2008-04-21
Posts: 375
Website

Re: rtorrent daemon

Thanks, i use it for hellanzb now, maybe you can make a wiki page for this!

Offline

#4 2008-10-20 05:28:14

andywxy
Member
From: Winnipeg, Canada
Registered: 2007-09-27
Posts: 36

Re: rtorrent daemon

It's so nice! Great job! Thanks big_smile

Offline

#5 2008-10-20 11:42:26

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: rtorrent daemon

Oh . . . nice.

Offline

#6 2008-10-28 10:04:04

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: rtorrent daemon

#!/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

#7 2008-10-29 00:58:37

Heller_Barde
Member
Registered: 2008-04-01
Posts: 245

Re: rtorrent daemon

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

#8 2008-10-29 03:04:44

timetrap
Member
From: Here and There
Registered: 2008-06-05
Posts: 342
Website

Re: rtorrent daemon

Heller_Barde wrote:

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

#9 2008-11-22 23:05:52

TheBodziO
Member
From: Dukla, Poland
Registered: 2006-07-28
Posts: 228
Website

Re: rtorrent daemon

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… wink

Offline

#10 2011-06-16 23:06:21

Median
Member
Registered: 2011-06-03
Posts: 54

Re: rtorrent daemon

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)

Online

#11 2011-06-17 09:02:13

Median
Member
Registered: 2011-06-03
Posts: 54

Re: rtorrent daemon

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?

Online

#12 2011-06-17 09:17:16

karol
Archivist
Registered: 2009-05-06
Posts: 25,433

Re: rtorrent daemon

I think you should start a new thread.
Do you have screen installed?

Offline

#13 2011-06-17 11:16:32

Median
Member
Registered: 2011-06-03
Posts: 54

Re: rtorrent daemon

I do, and i guess i will.

Online

Board footer

Powered by FluxBB