FreeBSD Script
Posted: Mon Dec 26, 2011 7:02 am
Sharing this so I don't have to spend a day making at again when I lose it
X-Mas ended up being productive after all
It will have to do until I have time for the complete Re write which will be nxt x-mas
I did have another script that automatically adjusted its self for other rc.d names but I accidentally overwritten it
for those that want stop to work you will have to find your java install path
and change
procname=/usr/local/diablo-jdk1.6.0/bin/java
also change
RatioKeeper_flags="${RatioKeeper_flags:-"-ui:1"}"
to
RatioKeeper_flags="${RatioKeeper_flags:-"-ui:0"}"
I left it like that for testing when its all working just change it to 0 and when you reboot it will be a daemon
Code has been updated to support the new features of the TRK test file

X-Mas ended up being productive after all
It will have to do until I have time for the complete Re write which will be nxt x-mas

I did have another script that automatically adjusted its self for other rc.d names but I accidentally overwritten it
for those that want stop to work you will have to find your java install path
and change
procname=/usr/local/diablo-jdk1.6.0/bin/java
also change
RatioKeeper_flags="${RatioKeeper_flags:-"-ui:1"}"
to
RatioKeeper_flags="${RatioKeeper_flags:-"-ui:0"}"
I left it like that for testing when its all working just change it to 0 and when you reboot it will be a daemon
Code has been updated to support the new features of the TRK test file
Code: Select all
#!/bin/sh
# PROVIDE: RatioKeeper
# BEFORE: DAEMON
# KEYWORD: shutdown
## Add RatioKeeper_enable="YES" in /etc/rc.conf
## echo 'RatioKeeper_enable="YES"'>>/etc/rc.conf
## save file as RatioKeeper in /usr/local/etc/rc.d/
## Please Contain RatioKeeper in its own Folder for Security reasons; because this script changes RatioKeepers home folder permissions
## RatioKeeper_flags=
##
## -ui:1|0 (launch TRK with gui or without. Default - 1)
## -active:1|0 (Activate TRK for the new tracker (Default Settings). Default value is 1)
## -upinc:0..1000 (Increase Uploaded Traffic for the new tracker (Default Settings). Default value is 75(%))
## -downdec:0..100 (Decrease Downloaded Traffic for the new tracker (Default Settings). Default value is 0, turned off)
## -seeder:1|0 (Turn on Seeder mode for the new tracker (Default Settings). Default value is 0)
## -noup:1|0 (Emulate Upload Problems for the new tracker (Default Settings). Default value is 0)
## -blocktracker:1|0 (Block Tracker Communications for the new tracker (Default Settings). Default value is 0)
## --- Add x-y% of downloaded to uploaded ---
## -adddowntoup:1|0 (Add x-y% of downloaded to uploaded for the new tracker (Default Settings). Default value is 0)
## -adddowntoupx:0..100000 (X of adddowntoup for the new tracker (Default Settings). Default value is 25)
## -adddowntoupy:0..100000 (Y of adddowntoup for the new tracker (Default Settings). Default value is 33)
## --- Limit torrent fake upload speed ---
## -limtorrent:1|0 (Make sure that your fake upload increase speed for single .torrent doesn't exceed X-Y kb/s for the new tracker (Default Settings). Default value is 0, turned off)
## -limtorrentx:0..100000 (X kb/s of limtorrent for the new tracker (Default Settings). Default value is 100)
## -limtorrenty:0..100000 (Y kb/s of limtorrent for the new tracker (Default Settings). Default value is 150
## --- Settings ---
## -port:1..65535 (TRK listens this port. You need to setup your torrent client to use the port as HTTP proxy. Default port is 3012. Example: localhost:3012)
## -lc:<TRK_license_key> (The license key activates TRK on your PC.)
## --help (display this help and exit)
##
## --- Options Available for New Versions ---
## http://www.torrentratiokeeper.com/download/TorrentRatioKeeperMonsterTest.jar
## -dir:/path ( Location of TRK settings )
##
## Example: RatioKeeper_flags="${RatioKeeper_flags:-"-ui:0 -seeder:1 -noup:0 -upinc:112 -downdec:0"}"
name=RatioKeeper
procname=/usr/local/diablo-jdk1.6.0/bin/java
Java_bin="${Java_bin:-"/usr/local/bin/java"}"
Java_arg="${Java_arg:-"-jar"}"
RatioKeeper_enable="${RatioKeeper_enable:-"NO"}"
RatioKeeper_home="${RatioKeeper_home:-"/usr/daemons/TRKM"}"
RatioKeeper_config="${RatioKeeper_config:-"-dir:/usr/daemons/TRKM"}"
#RatioKeeper_license="${RatioKeeper_license:-"-lc:XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"}"
RatioKeeper_jar="${RatioKeeper_jar:-"TorrentRatioKeeperMonster.jar"}"
RatioKeeper_flags="${RatioKeeper_flags:-"-ui:1"}"
RatioKeeper_user="${RatioKeeper_user:-"daemon"}"
. /etc/rc.subr
rcvar=`set_rcvar`
pidfile="/var/run/${name}/pid"
start_precmd=RatioKeeper_prestart
stop_postcmd=RatioKeeper_poststop
if [ -n "${RatioKeeper_java_home}" ] ; then
export JAVA_HOME="${RatioKeeper_java_home}"
fi
chmod -v -R 0777 ${RatioKeeper_home}
chown -v -R ${RatioKeeper_user} ${RatioKeeper_home}
required_files="${RatioKeeper_home}/${RatioKeeper_jar}"
java_command="$Java_bin $Java_arg $RatioKeeper_home/$RatioKeeper_jar"
command="/usr/sbin/daemon"
flags="-f -p ${pidfile} ${java_command} ${RatioKeeper_config} ${RatioKeeper_license} ${RatioKeeper_flags} ${log_args}"
echo $flags
RatioKeeper_prestart()
{
if [ "$RatioKeeper_user" = 'root' ]; then
err 1 "You must set RatioKeeper_user to a unprivileged user"
fi
if [ ! -d "/var/run/${name}" ]; then
if [ -e "/var/run/${name}" ]; then
unlink /var/run/${name}
fi
mkdir -p /var/run/${name}
fi
chmod 0755 /var/run/${name}
chown -R ${RatioKeeper_user} /var/run/${name}
}
RatioKeeper_poststop()
{
[ -e "$pidfile" ] && unlink $pidfile
[ -d "${pidfile%/pid}" ] && rmdir ${pidfile%/pid}
[ -e "$RatioKeeper_logfile" -a ! -s "$RatioKeeper_logfile" ] &&
unlink $RatioKeeper_logfile
}
load_rc_config "${name}"
# ${RatioKeeper_loglevel:="error"}
# ${RatioKeeper_logfile:="/var/tmp/${name}.log"}
required_dirs="$RatioKeeper_home"
command_args="-c $required_dirs -L $RatioKeeper_loglevel -l $RatioKeeper_logfile -P $pidfile"
run_rc_command "$1"