You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2014/05/27 10:42:35 UTC
[2/2] git commit: updated refs/heads/4.4 to d298546
CLOUDSTACK-6328: run.sh check if an existing java process is running, before spawining new ones
Signed-off-by: Jayapal <ja...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/d298546c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/d298546c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/d298546c
Branch: refs/heads/4.4
Commit: d298546ccce201c5662f82363ba1300f04320e7e
Parents: 9bb35ce
Author: Saurav Lahiri <sa...@sungard.com>
Authored: Tue Apr 15 12:08:11 2014 +0000
Committer: Daan Hoogland <da...@onecht.net>
Committed: Tue May 27 10:42:23 2014 +0200
----------------------------------------------------------------------
systemvm/patches/debian/config/etc/init.d/cloud | 14 ++++-----
systemvm/scripts/run.sh | 30 +++++++++++++++-----
systemvm/scripts/utils.sh | 21 ++++++++++++++
3 files changed, 50 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d298546c/systemvm/patches/debian/config/etc/init.d/cloud
----------------------------------------------------------------------
diff --git a/systemvm/patches/debian/config/etc/init.d/cloud b/systemvm/patches/debian/config/etc/init.d/cloud
index 83853bc..b18b8b1 100755
--- a/systemvm/patches/debian/config/etc/init.d/cloud
+++ b/systemvm/patches/debian/config/etc/init.d/cloud
@@ -75,17 +75,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
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d298546c/systemvm/scripts/run.sh
----------------------------------------------------------------------
diff --git a/systemvm/scripts/run.sh b/systemvm/scripts/run.sh
index 146d96f..b6a3a27 100755
--- a/systemvm/scripts/run.sh
+++ b/systemvm/scripts/run.sh
@@ -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
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/d298546c/systemvm/scripts/utils.sh
----------------------------------------------------------------------
diff --git a/systemvm/scripts/utils.sh b/systemvm/scripts/utils.sh
new file mode 100644
index 0000000..4d55fc7
--- /dev/null
+++ b/systemvm/scripts/utils.sh
@@ -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
+}