Skip to content

Commit 96b1c6b

Browse files
lsauravJayapal
authored andcommitted
CLOUDSTACK-6328: run.sh check if an existing java process is running, before spawining new ones
Signed-off-by: Jayapal <jayapal@apache.org>
1 parent 6f244f3 commit 96b1c6b

3 files changed

Lines changed: 50 additions & 15 deletions

File tree

systemvm/patches/debian/config/etc/init.d/cloud

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,15 @@ _failure() {
8181
}
8282
RETVAL=$?
8383
CLOUDSTACK_HOME="/usr/local/cloud"
84+
if [ -f $CLOUDSTACK_HOME/systemvm/utils.sh ];
85+
then
86+
. $CLOUDSTACK_HOME/systemvm/utils.sh
87+
else
88+
_failure
89+
fi
8490

8591
# mkdir -p /var/log/vmops
8692

87-
get_pids() {
88-
local i
89-
for i in $(ps -ef| grep java | grep -v grep | awk '{print $2}');
90-
do
91-
echo $(pwdx $i) | grep "$CLOUDSTACK_HOME" | awk -F: '{print $1}';
92-
done
93-
}
94-
9593
start() {
9694
local pid=$(get_pids)
9795
if [ "$pid" != "" ]; then

systemvm/scripts/run.sh

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,31 @@
2323
#_run.sh runs the agent client.
2424

2525
# set -x
26-
26+
readonly PROGNAME=$(basename "$0")
27+
readonly LOCKDIR=/tmp
28+
readonly LOCKFD=500
29+
30+
CLOUDSTACK_HOME="/usr/local/cloud"
31+
. $CLOUDSTACK_HOME/systemvm/utils.sh
32+
33+
LOCKFILE=$LOCKDIR/$PROGNAME.xlock
34+
lock $LOCKFILE $LOCKFD
35+
if [ $? -eq 1 ];then
36+
exit 1
37+
fi
38+
2739
while true
2840
do
29-
./_run.sh "$@" &
30-
wait
31-
ex=$?
32-
if [ $ex -eq 0 ] || [ $ex -eq 1 ] || [ $ex -eq 66 ] || [ $ex -gt 128 ]; then
33-
# permanent errors
34-
sleep 5
41+
pid=$(get_pids)
42+
action=`cat /usr/local/cloud/systemvm/user_request`
43+
if [ "$pid" == "" ] && [ "$action" == "start" ] ; then
44+
./_run.sh "$@" &
45+
wait
46+
ex=$?
47+
if [ $ex -eq 0 ] || [ $ex -eq 1 ] || [ $ex -eq 66 ] || [ $ex -gt 128 ]; then
48+
# permanent errors
49+
sleep 5
50+
fi
3551
fi
3652

3753
# user stop agent by service cloud stop

systemvm/scripts/utils.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
CLOUDSTACK_HOME="/usr/local/cloud"
4+
5+
get_pids() {
6+
local i
7+
for i in $(ps -ef| grep java | grep -v grep | awk '{print $2}');
8+
do
9+
echo $(pwdx $i) | grep "$CLOUDSTACK_HOME" | awk -F: '{print $1}';
10+
done
11+
}
12+
13+
lock()
14+
{
15+
lockfile=$1
16+
lockfd=$2
17+
eval "exec $lockfd>$lockfile"
18+
flock -n $lockfd\
19+
&& return 0 \
20+
|| return 1
21+
}

0 commit comments

Comments
 (0)