rtorrent init script and pid file

Hi all,

I have a created an init script for rtorrent, to run as a deamon. Problem is the pid files is not created. Don't think it's a permission problem, because running the rtorrent daemon as root instead of "gettons" user it won't be created anyway.
This is the rc script file.

Code:
#!/bin/sh
#
# FreeBSD rtorrent script 2011/03/11
#

# PROVIDE: rtorrent
# REQUIRE: LOGIN NETWORKING
# KEYWORD: shutdown

. /etc/rc.subr

PATH=$PATH:/usr/bin:/usr/local/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin
name="rtorrent"
rcvar=`set_rcvar`
required_files="/home/gettons/.rtorrent.rc"
command="su gettons -c 'screen -d -m -S rtorrent rtorrent'" 
start_precmd="rtorrent_precmd"
pidfile="/var/run/rtorrent"

load_rc_config $name

rtorrent_precmd()
{
	(
	# Can't do anything if rtorrent not installed
	[ -x /usr/local/bin/rtorrent ] || {
		warn "/usr/loca/bin/rtorrent does not exist."
		echo "===================================================="
		echo "rtorrent not found"
		echo "===================================================="
		return 1
	}
	if [ -f /home/gettons/.rtorrent.rc ]; then
		echo "Reading gettons rtorrent conf file" \
		    "located at /home/gettons/.rtorrent.rc"
	else
		echo "/home/gettons/.rtorrent.rc not found!"    
	fi
	)
}

load_rc_config $name
run_rc_command "$1"
 
Why not simply install sysutils/tmux and put this in the rtorrent user's crontab?

Code:
@reboot /usr/local/bin/tmux new-session -d '/usr/local/bin/rtorrent'

Works like a charm, starts rtorrent at boot-time, will keep it running until you choose to stop it (with ctl-q in rtorrent), and you can always enter and leave the running rtorrent session any time you like by attaching to or detaching from the tmux session. This in fact daemonises rtorrent under the user's privileges, leaving everything (paths, PIDs, rights) intact.
 
Back
Top