Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
executable file 299 lines (264 sloc) 6.55 KB
#!/bin/bash
#
# chkconfig: 2345 99 05
# description: script for starting and stopping eucalyptus java ws services
#
### BEGIN INIT INFO
# Provides: eucalyptus-WS
# Required-Start: $remote_fs $syslog
# Should-Start: START
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Eucalyptus CONFNAME
# Description: Start the Eucalyptus CONFNAME
# 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 CONFNAME"
NAME=eucalyptus-WS
ANT="`which ant 2> /dev/null`"
JAVA="`which java 2> /dev/null`"
EUCA_USER="eucalyptus"
JAR_NAME="/usr/share/eucalyptus/eucalyptus-JARNAME-@VERSION@.jar"
JAR_ALL_NAMES="/usr/share/eucalyptus/eucalyptus-interface-@VERSION@.jar /usr/share/eucalyptus/eucalyptus-storagecontroller-@VERSION@.jar /usr/share/eucalyptus/eucalyptus-storagemgr-@VERSION@.jar"
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
# Read configuration variable file if it is present
if [ -r $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf ]; then
EUCA_TMP="$EUCALYPTUS"
. $EUCALYPTUS/etc/eucalyptus/eucalyptus.conf
# has eucalyptus been configured?
if [ "$EUCALYPTUS" = "not_configured" ]; then
echo "EUCALYPTUS not configured!"
exit 1
fi
# there may be inconsistencied between conf file and env variable
if [ "$EUCA_TMP" != "$EUCALYPTUS" ]; then
echo "Warning: you should check EUCALYPTUS in conf file"
fi
else
echo "Cannot find eucalyptus configuration file!"
exit 1
fi
export EUCALYPTUS
pidfile=$EUCALYPTUS/var/run/eucalyptus/eucalyptus-cloud.pid
# 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
$EUCALYPTUS/usr/sbin/eucalyptus-cloud -h $EUCALYPTUS -u $EUCA_USER --pidfile ${pidfile} -f -o $EUCALYPTUS/var/log/eucalyptus/cloud-output.log >/dev/null 2>&1
return $?
}
do_status() {
if [ ! -e ${EUCALYPTUS}${JAR_NAME} ]; then
# service is not running
return 1
fi
if [ -s ${pidfile} ]; then
pid=`cat ${pidfile} 2> /dev/null`
if ps ax|grep $pid|grep eucalyptus-cloud.pid > /dev/null ; then
# we are good
return 0
fi
fi
return 1
}
do_stop() {
# now stop the service
if [ -s "${pidfile}" ]; then
pid=`cat $pidfile 2> /dev/null`
else
return
fi
# let's way few seconds than kill harder
timeout=20
while [ $timeout -gt 0 ]; do
if do_status ; 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
}
# 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 $DESC 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
# let's stop the service before moving the jar
do_stop
# 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}
# 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)
$0 stop
$0 start
;;
status)
if do_status ; then
echo "$DESC 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.