CLOUDSTACK-6328: run.sh check if an existing java process is running, before spawining new ones

Signed-off-by: Jayapal <jayapal@apache.org>
This commit is contained in:
Saurav Lahiri 2014-04-15 12:08:11 +00:00 committed by Jayapal
parent 6f244f3eac
commit 96b1c6bf3c
3 changed files with 50 additions and 15 deletions

View File

@ -81,17 +81,15 @@ _failure() {
}
RETVAL=$?
CLOUDSTACK_HOME="/usr/local/cloud"
if [ -f $CLOUDSTACK_HOME/systemvm/utils.sh ];
then
. $CLOUDSTACK_HOME/systemvm/utils.sh
else
_failure
fi
# mkdir -p /var/log/vmops
get_pids() {
local i
for i in $(ps -ef| grep java | grep -v grep | awk '{print $2}');
do
echo $(pwdx $i) | grep "$CLOUDSTACK_HOME" | awk -F: '{print $1}';
done
}
start() {
local pid=$(get_pids)
if [ "$pid" != "" ]; then

View File

@ -23,15 +23,31 @@
#_run.sh runs the agent client.
# set -x
readonly PROGNAME=$(basename "$0")
readonly LOCKDIR=/tmp
readonly LOCKFD=500
CLOUDSTACK_HOME="/usr/local/cloud"
. $CLOUDSTACK_HOME/systemvm/utils.sh
LOCKFILE=$LOCKDIR/$PROGNAME.xlock
lock $LOCKFILE $LOCKFD
if [ $? -eq 1 ];then
exit 1
fi
while true
do
./_run.sh "$@" &
wait
ex=$?
if [ $ex -eq 0 ] || [ $ex -eq 1 ] || [ $ex -eq 66 ] || [ $ex -gt 128 ]; then
# permanent errors
sleep 5
pid=$(get_pids)
action=`cat /usr/local/cloud/systemvm/user_request`
if [ "$pid" == "" ] && [ "$action" == "start" ] ; then
./_run.sh "$@" &
wait
ex=$?
if [ $ex -eq 0 ] || [ $ex -eq 1 ] || [ $ex -eq 66 ] || [ $ex -gt 128 ]; then
# permanent errors
sleep 5
fi
fi
# user stop agent by service cloud stop

21
systemvm/scripts/utils.sh Normal file
View File

@ -0,0 +1,21 @@
#!/bin/bash
CLOUDSTACK_HOME="/usr/local/cloud"
get_pids() {
local i
for i in $(ps -ef| grep java | grep -v grep | awk '{print $2}');
do
echo $(pwdx $i) | grep "$CLOUDSTACK_HOME" | awk -F: '{print $1}';
done
}
lock()
{
lockfile=$1
lockfd=$2
eval "exec $lockfd>$lockfile"
flock -n $lockfd\
&& return 0 \
|| return 1
}