mirror of
				https://github.com/apache/cloudstack.git
				synced 2025-11-04 00:02:37 +01:00 
			
		
		
		
	Applying to the following directories: * api * deamonize * agnet * agent-simulator * cloud-cli
		
			
				
	
	
		
			89 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			89 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
# Licensed to the Apache Software Foundation (ASF) under one
 | 
						|
# or more contributor license agreements.  See the NOTICE file
 | 
						|
# distributed with this work for additional information
 | 
						|
# regarding copyright ownership.  The ASF licenses this file
 | 
						|
# to you under the Apache License, Version 2.0 (the
 | 
						|
# "License"); you may not use this file except in compliance
 | 
						|
# with the License.  You may obtain a copy of the License at
 | 
						|
# 
 | 
						|
#   http://www.apache.org/licenses/LICENSE-2.0
 | 
						|
# 
 | 
						|
# Unless required by applicable law or agreed to in writing,
 | 
						|
# software distributed under the License is distributed on an
 | 
						|
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 | 
						|
# KIND, either express or implied.  See the License for the
 | 
						|
# specific language governing permissions and limitations
 | 
						|
# under the License.
 | 
						|
 | 
						|
#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"
 | 
						|
 | 
						|
export PATH=/sbin:/usr/sbin:"$PATH"
 | 
						|
SERVICEARGS=
 | 
						|
for x in private public ; do
 | 
						|
	configuration=`grep "^$x.network.device" "@AGENTSYSCONFDIR@"/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 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 $SERVICEARGS &
 | 
						|
	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
 |