Return-Path: X-Original-To: apmail-cloudstack-commits-archive@www.apache.org Delivered-To: apmail-cloudstack-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3423E10278 for ; Tue, 27 May 2014 05:32:26 +0000 (UTC) Received: (qmail 54980 invoked by uid 500); 27 May 2014 05:32:26 -0000 Delivered-To: apmail-cloudstack-commits-archive@cloudstack.apache.org Received: (qmail 54946 invoked by uid 500); 27 May 2014 05:32:26 -0000 Mailing-List: contact commits-help@cloudstack.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cloudstack.apache.org Delivered-To: mailing list commits@cloudstack.apache.org Received: (qmail 54935 invoked by uid 99); 27 May 2014 05:32:26 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 May 2014 05:32:26 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id B764A9A6300; Tue, 27 May 2014 05:32:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jayapal@apache.org To: commits@cloudstack.apache.org Date: Tue, 27 May 2014 05:32:25 -0000 Message-Id: <16e1a0e59e5e48d2a7731096fa3553a4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] git commit: updated refs/heads/4.4-forward to 37a3a65 Repository: cloudstack Updated Branches: refs/heads/4.4-forward 2ab7bcade -> 37a3a65c7 CLOUDSTACK-6328: run.sh check if an existing java process is running, before spawining new ones Signed-off-by: Jayapal Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/587ee544 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/587ee544 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/587ee544 Branch: refs/heads/4.4-forward Commit: 587ee544f2d8223599e5ee8c56f926ebf7882b8c Parents: 2ab7bca Author: Saurav Lahiri Authored: Tue Apr 15 12:08:11 2014 +0000 Committer: Jayapal Committed: Tue May 27 10:56:04 2014 +0530 ---------------------------------------------------------------------- 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/587ee544/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/587ee544/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/587ee544/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 +}