hark said:I quickly whipped up an rc script to start/stop rtorrent but rtorrent is forking, such that the PID returned by $$ is invalid. Because of this, there's no good way to either get the status of the service or to stop it, which in my mind is completely useless. (link)
There's a variety of scripts available for starting rtorrent as a service on various Linux distributions (and even the 'official' init script), and they solve this "oh god where is the PID" problem by using a named screen session. It's a massive hack, but has the added advantage of letting you reattach to the screen and manipulate rtorrent that way. I'd rather just throw rtorrent startup into rc.local, as the poster above suggests.
root /data/incoming/torrents/session # cat rtorrent.lock
tonatiuh.p5ycho.net:+36874
cut -d + -f 2 $sessiondir/rtorrent.lock
#!/bin/sh
# This part is needed for proper startup at boot time and proper shutdown
# PROVIDE: rtorrent
# REQUIRE: NETWORKING DEAMON
# KEYWORD: shutdown
. /etc/rc.subr
# Set daemon name and the user running the btgdaemon
name="rtorrent"
rcvar=`set_rcvar`
user="rtorrent"
sessiondir=/data/incoming/torrents/session
# pidfile, your ${user} must be able to write this file!
#rtorrent_pidfile="${sessiondir}/rtorrenttest.lock"
# Location of the rtorrent configuration
#configfile="/home/${name}/.rtorrent.rc"
start_cmd="${name}_start"
stop_cmd="${name}_stop"
# Command to execute when starting the daemon
${name}_start()
{
su -l ${user} -c "/usr/local/bin/rtorrent -s ${sessiondir} &"
# -l or -m?
# -s overrides sessiondir in .rtorrent.rc
}
# Stopping the daemon (a bit of a hack)
${name}_stop()
{
kill -9 `cut -d + -f 2 $sessiondir/rtorrent.lock`
}
load_rc_config ${name}
run_rc_command "$1"