This is a little script i wrote which does 2 things.
First, it checks how much space is left in the users home directory (if you use zfs quotas or separate slices this is great)
If it finds there is enough space, it will check to see if rtorrent is already running, if it IST running, it will remove the lock file (if it is there) and start rtorrent.
If it is running it will exit.
Put this in cron as @reboot and or every 5 minutes to make sure rtorrent stays running. Also, add a line to .rtorrent.rc to make rtorrent automatically stop when close to full.
note: on some systems the script ITSELF will trigger the check IF it has the word "rtorrent" in the name so just name it something like chktorrent or whatever you like.
Remember to edit the variables to suit your needs
Code: [Select]
#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
SERVICE='rtorrent'
FILE="/usr/home/$USER/rtorrent/.session/rtorrent.lock"
HOMEDIR="/usr/home/$USER"
SIZE=95 #total %age
df $HOMEDIR| tail -1 | while read fs size used avail pcnt mount;
do
pcnt=$(echo ${pcnt} | cut -d'%' -f1 )
if [ ${pcnt} -ge $SIZE ]; then
echo "Running out of space \"${fs} (${pcnt}%)\" on ${HOSTNAME} as on $(date)"
exit 1
fi
if pgrep -u $USER $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
rm -f ${FILE}
echo "$SERVICE is not running, starting $SERVICE" && screen -d -m -S seedbox $SERVICE
fi
done
First, it checks how much space is left in the users home directory (if you use zfs quotas or separate slices this is great)
If it finds there is enough space, it will check to see if rtorrent is already running, if it IST running, it will remove the lock file (if it is there) and start rtorrent.
If it is running it will exit.
Put this in cron as @reboot and or every 5 minutes to make sure rtorrent stays running. Also, add a line to .rtorrent.rc to make rtorrent automatically stop when close to full.
note: on some systems the script ITSELF will trigger the check IF it has the word "rtorrent" in the name so just name it something like chktorrent or whatever you like.
Remember to edit the variables to suit your needs
Code: [Select]
#!/bin/sh
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/bin:/sbin
SERVICE='rtorrent'
FILE="/usr/home/$USER/rtorrent/.session/rtorrent.lock"
HOMEDIR="/usr/home/$USER"
SIZE=95 #total %age
df $HOMEDIR| tail -1 | while read fs size used avail pcnt mount;
do
pcnt=$(echo ${pcnt} | cut -d'%' -f1 )
if [ ${pcnt} -ge $SIZE ]; then
echo "Running out of space \"${fs} (${pcnt}%)\" on ${HOSTNAME} as on $(date)"
exit 1
fi
if pgrep -u $USER $SERVICE > /dev/null
then
echo "$SERVICE service running, everything is fine"
else
rm -f ${FILE}
echo "$SERVICE is not running, starting $SERVICE" && screen -d -m -S seedbox $SERVICE
fi
done