cloudstack/console-proxy/libexec/console-proxy-runner.in
2010-08-11 16:02:57 -07:00

72 lines
2.0 KiB
Bash
Executable File

#!/usr/bin/env bash
#run.sh runs the agent client.
cd `dirname "$0"`
SYSTEMJARS="@SYSTEMJARS@"
SCP=$(build-classpath $SYSTEMJARS) ; if [ $? != 0 ] ; then SCP="@SYSTEMCLASSPATH@" ; fi
DCP="@DEPSCLASSPATH@"
ACP="@AGENTCLASSPATH@"
export CLASSPATH=$SCP:$DCP:$ACP:@CPSYSCONFDIR@
for jarfile in "@PREMIUMJAVADIR@"/* ; do
if [ ! -e "$jarfile" ] ; then continue ; fi
CLASSPATH=$jarfile:$CLASSPATH
done
for plugin in "@PLUGINJAVADIR@"/* ; do
if [ ! -e "$plugin" ] ; then continue ; fi
CLASSPATH=$plugin:$CLASSPATH
done
export CLASSPATH
set -e
cd "@CPLIBDIR@"
echo Current directory is "$PWD"
echo CLASSPATH to run the console proxy: "$CLASSPATH"
export PATH=/sbin:/usr/sbin:"$PATH"
SERVICEARGS=
for x in private public ; do
configuration=`grep -q "^$x.network.device" "@CPSYSCONFDIR@"/agent.properties || true`
if [ -n "$CONFIGURATION" ] ; then
echo "Using manually-configured network device $CONFIGURATION"
else
defaultroute=`ip route | grep ^default | cut -d ' ' -f 5`
test -n "$defaultroute"
echo "Using auto-discovered network device $defaultroute which is the default route"
SERVICEARGS="$SERVICEARGS $x.network.device="$defaultroute
fi
done
function termagent() {
if [ "$agentpid" != "" ] ; then
echo Killing VMOps Console Proxy "(PID $agentpid)" with SIGTERM >&2
kill -TERM $agentpid
echo Waiting for agent to exit >&2
wait $agentpid
ex=$?
echo Agent exited with return code $ex >&2
else
echo Agent PID is unknown >&2
fi
}
trap termagent TERM
while true ; do
java -Xms128M -Xmx384M -cp "$CLASSPATH" "$@" com.cloud.agent.AgentShell $SERVICEARGS &
agentpid=$!
echo "Console Proxy started. PID: $!" >&2
wait $agentpid
ex=$?
if [ $ex -gt 128 ]; then
echo "wait on console proxy process interrupted by SIGTERM" >&2
exit $ex
fi
echo "Console proxy exited with return code $ex" >&2
if [ $ex -eq 0 ] || [ $ex -eq 1 ] || [ $ex -eq 66 ] || [ $ex -gt 128 ]; then
echo "Exiting..." > /dev/stderr
exit $ex
fi
echo "Restarting console proxy..." > /dev/stderr
sleep 1
done