Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 311 lines (278 sloc) 6.896 kb
#!/bin/bash
#
# Init script for the Eucalyptus cloud manager services.
#
# chkconfig: 2345 99 05
# description: script for starting and stopping eucalyptus cloud services
#
### BEGIN INIT INFO
# Provides: eucalyptus-cloud
# Required-Start: $remote_fs $syslog
# Should-Start: sendmail
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Eucalyptus cloud controller
# Description: Start the Eucalyptus cloud controller
# X-UnitedLinux-Default-Enabled: yes
### END INIT INFO
#
# Do NOT "set -e"
# we need to source the current path in case of manual intallation
export PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
DESC="Eucalyptus cloud controller"
NAME=eucalyptus-cloud
JAR_NAME="/usr/share/eucalyptus/eucalyptus-interface.jar"
JAR_ALL_NAMES="/usr/share/eucalyptus/eucalyptus-interface.jar /usr/share/eucalyptus/eucalyptus-storagecontroller.jar /usr/share/eucalyptus/eucalyptus-storagemgr.jar"
ANT="`which ant 2> /dev/null`"
JAVA="`which java 2> /dev/null`"
EUCA_USER="eucalyptus"
if [ "$EUID" != "0" ]; then
echo "Eucalyptus init scripts must be run as root."
exit 1
fi
# if we have lsb functions let's source them
WE_HAVE_LSB="N"
if [ -e /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
# very old lsb don't have the functions we need
if type log_daemon_msg > /dev/null 2> /dev/null ; then
WE_HAVE_LSB="Y"
fi
fi
# honor the ENV variable if found otherwise look in root
if [ -z "$EUCALYPTUS" ] ; then
EUCALYPTUS="@prefix@"
if [ ! -e ${EUCALYPTUS}/etc/eucalyptus/eucalyptus.conf ] ; then
EUCALYPTUS="/"
fi
fi
export EUCALYPTUS
# just a quick way to check if we have the package still installed: at
# times we can still have the init.d script
if [ ! -x $EUCALYPTUS/usr/sbin/euca_conf ]; then
echo "Some eucalyptus components are missing"
exit 1
fi
check_java() {
java_min_version="1.6.0"
# we need a good JAVA_HOME
if [ -z "$JAVA_HOME" ]; then
# user didn't setup JAVA_HOME, let's look for it
if [ -z "$JAVA" ]; then
echo "Cannot find java!"
exit 1
fi
JAVA_HOME="`readlink -f $JAVA`"
JAVA_HOME="`dirname $JAVA_HOME|sed 's:/jre/bin::'`"
if [ ! -d $JAVA_HOME ]; then
echo "Cannot find a good JAVA_HOME"
exit 1
fi
fi
# to be sure we are using the right java/JAVA_HOME
JAVA="$JAVA_HOME/jre/bin/java"
# let's see if we can find a decent java
if [ -x "$JAVA" ]; then
java_version=`$JAVA -version 2>&1 | grep "java version" | sed -e 's/.*java version "\(.*\)".*/\1/'`
if [ `expr $java_version "<" $java_min_version` -eq 0 ]; then
export JAVA_HOME
return
fi
fi
echo "Eucalyptus needs java version >= $java_min_version"
exit 1
}
do_start() {
local ret
# basic checks
check_java
if ! $EUCALYPTUS/usr/sbin/euca_conf -check cloud ; then
exit 1
fi
cd $EUCALYPTUS/etc/eucalyptus
(su -p $EUCA_USER -c "/bin/bash $ANT -f cloud.xml run" > $EUCALYPTUS/var/log/eucalyptus/cloud-output.log 2>&1) &
ret="$?"
echo "$!" > $EUCALYPTUS/var/run/eucalyptus/eucalyptus-cloud.pid
return $ret
}
do_status() {
if [ ! -e ${EUCALYPTUS}${JAR_NAME} ]; then
# service is not running
return 1
fi
pidfile=$EUCALYPTUS/var/run/eucalyptus/eucalyptus-cloud.pid
if [ -s $pidfile ]; then
pid=`cat $pidfile 2> /dev/null`
if ps ax|grep $pid|grep cloud.xml> /dev/null ; then
# we are good
return 0
fi
fi
return 1
}
do_stop() {
pidfile=$EUCALYPTUS/var/run/eucalyptus/eucalyptus-cloud.pid
# now kill the service
if [ -s "$pidfile" ]; then
pid=`cat $pidfile 2> /dev/null`
kill $pid 2> /dev/null >/dev/null
else
return
fi
# let's way few seconds than kill harder
timeout=5
while [ $timeout -gt 0 ]; do
if ps $pid > /dev/null 2>&1 ; then
sleep 1
timeout=$(($timeout - 1))
else
break
fi
done
if [ $timeout -eq 0 ]; then
kill -9 $pid > /dev/null 2>&1
fi
rm -f $pidfile
}
# Read configuration variable file if it is present
if [ -r $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf ]; then
. $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf
else
echo "Cannot find eucalyptus configuration file!"
exit 1
fi
if [ "$EUCALYPTUS" = "not_configured" ]; then
echo "EUCALYPTUS not configured!"
exit 1
fi
# let's get the user to use
if [ -z "$EUCA_USER" ] ; then
EUCA_USER="root"
fi
# set the library path correctly
export LD_LIBRARY_PATH="$EUCALYPTUS/usr/lib/eucalyptus:$LD_LIBRARY_PATH"
case "$1" in
start)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_daemon_msg "Starting $DESC" "$NAME"
else
echo -n "Starting $DESC: "
fi
fi
# let's check there is no previous cloud running
if do_status ; then
echo
echo "another CLC is already running!"
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 1
fi
fi
exit 1
fi
# move the jar in the right place
if [ -e ${EUCALYPTUS}${JAR_NAME}.disabled ]; then
if ! cp ${EUCALYPTUS}${JAR_NAME}.disabled ${EUCALYPTUS}${JAR_NAME} ; then
echo "Failed to copy jar file into place!"
exit 1
fi
rm -f ${EUCALYPTUS}${JAR_NAME}.disabled
fi
# since other services could be running, we stop the container
# before starting
do_stop
do_start
case "$?" in
0|1)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 0
else
echo "done."
fi
fi
;;
*)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 1
else
echo "failed!"
fi
fi
;;
esac
;;
stop)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_begin_msg "Stopping $DESC"
else
echo -n "Stopping $DESC: "
fi
fi
# if we don't have the JAR file we are not running
if [ ! -e ${EUCALYPTUS}${JAR_NAME} ]; then
# service is not running
exit 0
fi
# move the jar in the right place
if ! cp ${EUCALYPTUS}${JAR_NAME} ${EUCALYPTUS}${JAR_NAME}.disabled ; then
echo "Failed to copy jar file into place!"
exit 1
fi
rm -f ${EUCALYPTUS}${JAR_NAME}
# now let's stop the service
do_stop
# if we have more services running, we'll need to restart
__restart="N"
for x in $JAR_ALL_NAMES ; do
if [ -e ${EUCALYPTUS}/${x} ]; then
__restart="Y"
break
fi
done
if [ ${__restart} = "Y" ]; then
do_start
fi
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 0
else
echo "done."
fi
fi
;;
restart)
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_begin_msg "Restarting $DESC"
else
echo -n "Restarting $DESC: "
fi
fi
do_stop
do_start
if [ "$VERBOSE" != no ]; then
if [ "$WE_HAVE_LSB" = "Y" ]; then
log_end_msg 0
else
echo "done."
fi
fi
;;
status)
if do_status ; then
echo "CLC is running"
else
exit 3
fi
;;
*)
echo "Usage: $NAME {start|stop|restart}" >&2
exit 3
;;
esac
:
Jump to Line
Something went wrong with that request. Please try again.