mirror of https://github.com/apache/cloudstack.git
58 lines
1.4 KiB
Bash
Executable File
58 lines
1.4 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:@AGENTSYSCONFDIR@
|
|
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 "@AGENTLIBDIR@"
|
|
echo Current directory is "$PWD"
|
|
echo CLASSPATH to run the agent: "$CLASSPATH"
|
|
|
|
function termagent() {
|
|
if [ "$agentpid" != "" ] ; then
|
|
echo Killing VMOps Agent "(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 &
|
|
agentpid=$!
|
|
echo "Agent started. PID: $!" >&2
|
|
wait $agentpid
|
|
ex=$?
|
|
if [ $ex -gt 128 ]; then
|
|
echo "wait on agent process interrupted by SIGTERM" >&2
|
|
exit $ex
|
|
fi
|
|
echo "Agent 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 agent..." > /dev/stderr
|
|
sleep 1
|
|
done
|