It has been a frequently asked question on how to start rtorrent at boot or how to make an init script.
The answer is to simply use the user's crontab.
Init scripts are meant for system wide daemons. While you _can_ make init start rtorrent for a user it is not correct practice.
Code:
#!/usr/bin/env bash
USER=${USER:-$1}
PATH=${PATH:-"/usr/local/bin:/usr/bin:/bin:/home/$USER/bin"}
## [USAGE] crontab -e
## Examples:
# Run every minute * * * * * ~/rtorrent_cron <username>
# every 10 minues */10 * * * * ~/rtorrent_cron
# on reboot @reboot ~/rtorrent_cron
# hourly @hourly ~/rtorrent_cron
COMMAND="dtach -n /home/$USER/rtorrent.dtach rtorrent"
#COMMAND="tmux new -s rtorrent -d rtorrent"
#COMMAND="screen -dmS rtorrent rtorrent"
## Uncomment if you want to log these actions
#LOG=/home/$USER/rtorrent_cron.log
#MSG="$(date "+[%d %b %H:%M:%S]") CRON: Starting rtorrent..."
start_rtorrent() { #test if rtorrent is running, if not, start it
if [[ -z $(pgrep -u $USER rtorrent) ]]; then
$($COMMAND) && sleep 1
[[ $LOG && ! -z $(pgrep -u $USER rtorrent) ]] &&
echo "$MSG ok!" >>$LOG || echo "$MSG FAILED" >>$LOG
fi
}
start_rtorrent >/dev/null
exit 0
To grab this script in one command run
Code:
wget 'http://pastebin.com/raw.php\?i\=CB4ba35C' -O ~/rtorrent_cron && chmod +x ~/rtorrent_cron
you may need to pass a <username> arg at the end of the script for ancient cron daemons
uncomment the COMMAND variable you use on your system, dtach/tmux/screen
uncomment the LOG and MSG variables if you want to see some action logged
Read the USAGE and your golden.
The answer is to simply use the user's crontab.
Init scripts are meant for system wide daemons. While you _can_ make init start rtorrent for a user it is not correct practice.
Code:
#!/usr/bin/env bash
USER=${USER:-$1}
PATH=${PATH:-"/usr/local/bin:/usr/bin:/bin:/home/$USER/bin"}
## [USAGE] crontab -e
## Examples:
# Run every minute * * * * * ~/rtorrent_cron <username>
# every 10 minues */10 * * * * ~/rtorrent_cron
# on reboot @reboot ~/rtorrent_cron
# hourly @hourly ~/rtorrent_cron
COMMAND="dtach -n /home/$USER/rtorrent.dtach rtorrent"
#COMMAND="tmux new -s rtorrent -d rtorrent"
#COMMAND="screen -dmS rtorrent rtorrent"
## Uncomment if you want to log these actions
#LOG=/home/$USER/rtorrent_cron.log
#MSG="$(date "+[%d %b %H:%M:%S]") CRON: Starting rtorrent..."
start_rtorrent() { #test if rtorrent is running, if not, start it
if [[ -z $(pgrep -u $USER rtorrent) ]]; then
$($COMMAND) && sleep 1
[[ $LOG && ! -z $(pgrep -u $USER rtorrent) ]] &&
echo "$MSG ok!" >>$LOG || echo "$MSG FAILED" >>$LOG
fi
}
start_rtorrent >/dev/null
exit 0
To grab this script in one command run
Code:
wget 'http://pastebin.com/raw.php\?i\=CB4ba35C' -O ~/rtorrent_cron && chmod +x ~/rtorrent_cron
you may need to pass a <username> arg at the end of the script for ancient cron daemons
uncomment the COMMAND variable you use on your system, dtach/tmux/screen
uncomment the LOG and MSG variables if you want to see some action logged
Read the USAGE and your golden.