Here is the ubero runner script, I call it uberorunner, you can call it what you want. Make sure none of the long lines wrap.
Grab the StuffIt archive here
Or copy everything between the Code lines.
Your first line should be the #!/bin/sh line.
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
#!/bin/sh
#
# Uberorunner version .<font color = blue>9</font>
# This script assumes Ubero is installed in /Applications/Ubero and
# if you have a Dual Processor a second copy is in /Applications/Ubero2
# It is assumed you have manually setup your ubero agent(s) by running
# them once from the Finder and entering your registration info.
# This script must be in the (first) Ubero directory.
#
# ---------------------------------
# User Config Section
#
# Comment out (put a # in front of the DEBUG) if you have run the script
# once and know everything is working fine.
# It will no longer builtin echo out what is going on.
DEBUG=<font color = blue>1</font>
# amount of niceness: <font color = blue>-20</font> to <font color = blue>+20</font>: include the sign(-/+)
# <font color = blue>+20</font> is very very nice: lets you use the machine for other stuff
# <font color = blue>-20</font> is not at all nice: hogs as much CPU as possible
# you must launch the script as root to use negative values
myNice=<font color = blue>-20</font>
# Directory where your Ubero client lives
uberoDir=<font color = red>"/Applications/Ubero"</font>
# Directory where your second Ubero client lives (only for dual)
uberoDir2=<font color = red>"/Applications/Ubero2"</font>
#
# The next three settings you probably don't need to mess with
#
# Uncomment (remove the #) the next line if you have a Dual yet only
# want to run one Ubero Agent.
#onlyOne=<font color = blue>1</font>
# Comment (Add a # in front of autoStart) the next line if you dont
# want this script to be run automatically at startup via cron.
# ie You don't want the Ubero agent to automatically start after reboot.
# If you have previously run the script with autoStart enabled you will
# need to delete root's crontab by doing crontab -r as root.
autoStart=<font color = blue>1</font>
#
# Comment out (add a # in front of reLaunch) if you do NOT want this
# script to restart itself once a day.
# This can keep the agent(s) going if there are problems with running
# this script for several days.
reLaunch=<font color = blue>1</font>
# end user config
# ---------------------------------
#
# Don't change anything below here unless you know what you are doing!!
# ==================================
#
# Get the name of this script in case the user didnt follow directions.
runnerName=$<font color = blue>0</font>
runnerName=`basename $runnerName`
if [ $DEBUG ]; then
builtin echo Script Name $runnerName
fi
# Check to be sure this script is in the first Ubero Directory
cd $uberoDir
if [ ! -e <font color = red>"$runnerName"</font> ]; then
builtin echo <font color = red>"The runner script must be in the Ubero directory."</font>
exit <font color = blue>1</font>
fi
# Check root's crontab and set Ubero to run at reboot
if [ $autoStart ]; then
if [ ! -e ./uberotab ]; then
builtin echo <font color = red>"@reboot cd \"</font>$uberoDir\<font color = red>"; ./$runnerName &"</font> > uberotab
# Check if root already has a crontab so we don't mess with it.
if [ -e /var/cron/tabs/root ]; then
builtin echo <font color = red>"Root already has a crontab set up"</font>
builtin echo <font color = red>"You must manually add the line in "</font>
builtin echo <font color = red>"the file uberotab to root's crontab"</font>
else
# add uberotab as root's crontab
crontab ./uberotab
fi
else
# ubertab already exist so assume it was already set up by
# this script or the user
if [ $DEBUG ]; then
builtin echo <font color = red>"Assuming crontab is already set up."</font>
builtin echo <font color = red>"you can verify by doing crontab -l as root"</font>
builtin echo <font color = red>"If it is not, either add the line from the file"</font>
builtin echo <font color = red>"uberotab to your existing crontab file, or if you"</font>
builtin echo <font color = red>"have no crontab file, simply do crontab ./uberotab"</font>
builtin echo <font color = red>"as root while in the Ubero directory"</font>
fi
fi
fi
# up the number of allowed processes to avoid filling job table
# Check SHELL env since some folks have BASH as their /bin/sh and
# it uses different syntax.
if [ $ZSH_VERSION ]; then
ulimit -u <font color = blue>256</font>
else
limit maxproc <font color = blue>256</font>
fi
# Get the number of cpus
numCPU=`sysctl -n hw.ncpu`
if [ $onlyOne ]; then
numCPU=<font color = blue>1</font>
fi
if [ $DEBUG ]; then
builtin echo onlyOne is $onlyOne
builtin echo numCPU $numCPU
fi
# Get total physical RAM
totRAM=`sysctl -n hw.physmem`
# convert RAM bytes to MB
totRAM=`expr $totRAM / <font color = blue>1048756</font>`
if [ $DEBUG ]; then
builtin echo Total RAM $totRAM
fi
# check and set mem sizes
# This will set the java tweak to a maximum of <font color = blue>600</font>/<font color = blue>200</font> for a single
# and half that for a Dual. These settings have been determined to be ideal.
if [ <font color = red>"$totRAM"</font> -le <font color = red>"<font color = blue>150</font>"</font> ]; then
jvSize=<font color = blue>100</font>
apSize=<font color = blue>33</font>
fi
if [ <font color = red>"$totRAM"</font> -gt <font color = red>"<font color = blue>150</font>"</font> ]; then
if [ <font color = red>"$totRAM"</font> -le <font color = red>"<font color = blue>319</font>"</font> ]; then
jvSize=<font color = blue>200</font>
apSize=<font color = blue>66</font>
fi
fi
if [ <font color = red>"$totRAM"</font> -ge <font color = red>"<font color = blue>320</font>"</font> ]; then
jvSize=<font color = blue>300</font>
apSize=<font color = blue>100</font>
fi
if [ <font color = red>"$totRAM"</font> -gt <font color = red>"<font color = blue>640</font>"</font> ]; then
jvSize=<font color = blue>600</font>
apSize=<font color = blue>200</font>
fi
# If Dual divide tweak settings by <font color = blue>2</font>
if [ <font color = red>"$numCPU"</font> -gt <font color = red>"<font color = blue>1</font>"</font> ]; then
jvSize=`expr $jvSize / <font color = blue>2</font>`
apSize=`expr $apSize / <font color = blue>2</font>`
fi
# ==========================
# If you wish to manually set the java tweak sizes, uncomment the
# following <font color = blue>2</font> lines (remove the #) and set them to what you want.
# Remember for Duals these numbers get divided by <font color = blue>2</font>
#jvSize=<font color = blue>300</font>
#apSize=<font color = blue>100</font>
# ==========================
if [ $DEBUG ]; then
builtin echo java Size $jvSize
builtin echo App Size $apSize
fi
# Build Ubero Command
javaTweak=<font color = red>"-Xms${jvSize}m -Xmx${jvSize}m -XX:NewSize=${apSize}m -XX:MaxNewSize=${apSize}m"</font>
# Special case for only 64Mb RAM which is too little for tweaking
# (or much of anything) Get more RAM!
if [ <font color = red>"$totRAM"</font> -eq <font color = red>"<font color = blue>64</font>"</font> ]; then
javaTweak=<font color = red>""</font>
fi
if [ $DEBUG ]; then
builtin echo java Tweak $javaTweak
fi
uberoCommand=<font color = red>"/usr/bin/java $javaTweak -cp Agent.jar ubero.agent.Agent -text"</font>
# counter for restarting script after half a day
counter=<font color = blue>0</font>
# minimum amount of CPU to assume client is stalled
minCPU=<font color = blue>2</font>
# Do a couple of check to make sure things are configured
# Make sure user set uberoDir correctly
if [ ! -e $uberoDir ]; then
builtin echo Ubero is not in `dirname $uberoDir`
exit <font color = blue>1</font>
fi
# Make sure Ubero agent has been configured via the GUI
if [ -e $uberoDir/agent.def ]; then
builtin echo The Ubero Agent must be lauched from the Finder the first time
exit <font color = blue>1</font>
fi
# Do same checks if on a Dual
if [ <font color = red>"$numCPU"</font> -gt <font color = red>"<font color = blue>1</font>"</font> ]; then
# Make sure user set uberoDir2 correctly
if [ ! -e $uberoDir2 ]; then
builtin echo Ubero2 is not in `dirname $uberoDir2`
exit <font color = blue>1</font>
fi
# Make sure Ubero2 agent has been configured via the GUI
if [ -e <font color = red>"$uberoDir2/agent.def"</font> ];then
builtin echo The Ubero2 Agent must be lauched from the Finder the first time
exit <font color = blue>1</font>
fi
fi
# Start the agent(s)
if [ $DEBUG ]; then
builtin echo launching first agent
fi
cd <font color = red>"$uberoDir"</font>
/usr/bin/nice -n $myNice /usr/bin/nohup $uberoCommand >&/dev/null &
myPID=$!
if [ $DEBUG ]; then
builtin echo myPID $myPID
fi
# If Dual processor, launch second agent.
if [ <font color = red>"$numCPU"</font> -gt <font color = red>"<font color = blue>1</font>"</font> ]; then
if [ $DEBUG ]; then
builtin echo launching second agent
fi
cd <font color = red>"$uberoDir2"</font>
/usr/bin/nice -n $myNice /usr/bin/nohup $uberoCommand >&/dev/null &
myPID2=$!
if [ $DEBUG ]; then
builtin echo myPID2 $myPID2
fi
fi
# Wait a minute to allow agents to start running
if [ $DEBUG ]; then
builtin echo Giving agents a chance to get going
fi
/bin/sleep <font color = blue>60</font>
# loop forever checking for idle agents
while [ <font color = blue>1</font> ]; do
# Increment counter
counter=`expr $counter + <font color = blue>1</font>`
if [ $DEBUG ]; then
builtin echo Count is $counter
fi
# Get the CPU utilization percentage of the myPID (ubero agent) process via ps
# and grep chopping out all the other fields and put it in myCPU
myCPU=`ps uwp $myPID | grep <font color = red>"java"</font> | grep -v grep | awk '{print $<font color = blue>3</font>}' | awk -F. '{print $<font color = blue>1</font>}'`
if [ $DEBUG ]; then
builtin echo myCPU is $myCPU
fi
# Check to see if myCPU is less than our desired minimum (minCPU)
if [ <font color = red>"$myCPU"</font> -lt <font color = red>"$minCPU"</font> ]; then
# wait a bit and make sure we arent just receiving data
/bin/sleep <font color = blue>45</font>
fi
# Check for final time before killing
if [ <font color = red>"$myCPU"</font> -lt <font color = red>"$minCPU"</font> ]; then
# Assume ubero has stalled(again) and kill the process
if [ $DEBUG ]; then
builtin echo Killing first agent
fi
/bin/kill <font color = blue>-9</font> $myPID
# wait <font color = blue>3</font> seconds for process to die
/bin/sleep <font color = blue>3</font>
if [ $DEBUG ]; then
builtin echo Launching first agent
fi
# change directory to the ubero client
cd <font color = red>"$uberoDir"</font>
# execute a new instance of the ubero client just like before
/usr/bin/nice -n $myNice /usr/bin/nohup $uberoCommand >&/dev/null &
myPID=$!
if [ $DEBUG ]; then
builtin echo myPID is $myPID
fi
fi
# If we have a Dual, run same checks as above on second agent
if [ <font color = red>"$numCPU"</font> -gt <font color = red>"<font color = blue>1</font>"</font> ]; then
myCPU2=`ps uwp $myPID2 | grep <font color = red>"java"</font> | grep -v grep | awk '{print $<font color = blue>3</font>}' | awk -F. '{print $<font color = blue>1</font>}'`
if [ $DEBUG ]; then
builtin echo myCPU2 is $myCPU2
fi
if [ <font color = red>"$myCPU2"</font> -lt <font color = red>"$minCPU"</font> ]; then
/bin/sleep <font color = blue>45</font>
fi
if [ <font color = red>"$myCPU2"</font> -lt <font color = red>"$minCPU"</font> ]; then
if [ $DEBUG ]; then
builtin echo killing second agent
fi
/bin/kill <font color = blue>-9</font> $myPID2
/bin/sleep <font color = blue>3</font>
if [ $DEBUG ]; then
builtin echo launching second agent
fi
cd <font color = red>"$uberoDir2"</font>
/usr/bin/nice -n $myNice /usr/bin/nohup $uberoCommand >&/dev/null &
myPID2=$!
if [ $DEBUG ]; then
builtin echo myPID2 is $myPID2
fi
fi
fi
if [ $DEBUG ]; then
builtin echo /bin/sleeping
fi
# sit idle for <font color = blue>300</font> seconds (<font color = blue>5</font> minutes) and check to see if ubero has stalled
/bin/sleep <font color = blue>300</font>
if [ $DEBUG ]; then
builtin echo waking
fi
# If reLaunch is set then check if we have run for a day
# (<font color = blue>288</font>*<font color = blue>5</font>=1500minutes) or so and kill the agents and restart this script.
if [ $reLaunch ]; then
if [ <font color = red>"$counter"</font> -ge <font color = red>"<font color = blue>288</font>"</font> ]; then
if [ $DEBUG ]; then
builtin echo killing all
fi
/bin/kill <font color = blue>-9</font> $myPID
if [ <font color = red>"$numCPU"</font> -gt <font color = red>"<font color = blue>1</font>"</font> ]; then
/bin/kill <font color = blue>-9</font> $myPID2
fi
cd <font color = red>"$uberoDir"</font>
./<font color = red>"$runnerName"</font> &
/bin/sleep <font color = blue>3</font>
exit <font color = blue>0</font>
fi
fi
# Repeat the above check(s) for idleness forever.
done
</font>[/code]
[ 04-15-2002: Message edited by: mikkyo ]