[Piuparts-commits] [SCM] piuparts git repository branch, master, updated. 0.51

David Steele dsteele at gmail.com
Wed May 15 10:09:51 UTC 2013


The following commit has been merged in the master branch:
commit 290799ecbc6f3e8326697f56806080c7ce8d8465
Author: David Steele <dsteele at gmail.com>
Date:   Thu May 17 21:49:13 2012 -0400

    Modify slave_run and slave_join for multiple slave support

diff --git a/slave-bin/slave_join b/slave-bin/slave_join
index 8e3fb26..b127e66 100755
--- a/slave-bin/slave_join
+++ b/slave-bin/slave_join
@@ -22,9 +22,22 @@ set -e
 # reattach to an existing slave session
 #
 
-SESSIONNAME=piuparts_slave_screen
+if [ -z "$1" ] ; then
+   SLAVENUM=0
+else
+   SLAVENUM=$1
+fi
+
+if ! `echo $SLAVENUM | grep -E -e "^[0-9]{1}$" >/dev/null` ; then
+   echo "slave must be identified as a number between 0 and 9"
+   exit
+fi
+
+SCREENLOG=/var/lib/piuparts/slave/screenlog.$SLAVENUM
 
-if screen -ls $SESSIONNAME | grep -q "No Sockets found" ; then
+if [ $(ps fax|grep piuparts-slave|grep slave/$SLAVENUM|grep -v grep |wc -l) != 0 ] ; then
+  screen -r -S piuparts-slave-screen -p $SLAVENUM -x
+else
   echo "piuparts-slave not running!"
   echo
   echo "ps faxu | grep piuparts"
diff --git a/slave-bin/slave_run.in b/slave-bin/slave_run.in
index 0fd78d0..8447c67 100755
--- a/slave-bin/slave_run.in
+++ b/slave-bin/slave_run.in
@@ -22,8 +22,16 @@ set -e
 # Run piuparts-slave in screen to allow interactive control later on.
 #
 
+if [ -z "$1" ] ; then
+   SLAVENUM=0
+else
+   SLAVENUM=$1
+fi
 
-. @sharedir@/piuparts/lib/read_config.sh
+if ! `echo $SLAVENUM | grep -E -e "^[0-9]{1}$" >/dev/null` ; then
+   echo "slave must be identified as a number between 0 and 9"
+   exit
+fi
 
 get_config_value PYTHONPATH global PYTHONPATH ''
 get_config_value SLAVEROOT global slave-directory
@@ -32,27 +40,40 @@ get_config_value PIUPARTS_TMPDIR global tmpdir
 
 export PYTHONPATH
 
-SESSIONNAME=piuparts_slave_screen
-SCREENLOG=$SLAVEROOT/screenlog.0
+SLAVEROOTDIR=/var/lib/piuparts/slave
+SLAVEDIR=$SLAVEROOTDIR/$SLAVENUM
 
-if ! screen -ls $SESSIONNAME | grep -q "No Sockets found" ; then
-	echo "piuparts-slave is already running!"
-	echo
-	screen -ls
-	exit 1
+if [ ! -d $SLAVEDIR ] ; then
+   install -d $SLAVEDIR
+   chown piupartss:piuparts $SLAVEDIR
 fi
 
-# cleanup cruft from previous runs
- at sharedir@/piuparts/slave/slave_cleanup
+SCREENLOG=$SLAVEROOTDIR/screenlog.$SLAVENUM
+MONITORDIR=/var/lib/piuparts/master/monitor-slave
+
+# prepare environment
 rm -f $SCREENLOG
 
-# ensure the temporary directory exists
-mkdir -p $PIUPARTS_TMPDIR
+cd $SLAVEROOTDIR
+(ps fax|grep -v grep| grep piuparts-slave | grep $SLAVEDIR ) && exit 0
+rm -f $SCREENLOG || :					# used by ~piupartsm/bin/detect_slave_problems
+rm -f $MONITORDIR/*					# used by several scripts to only warn once a day
+
+trap "cat $SCREENLOG | mail -s 'slave abnormaly ended' piupartsm ; rm $SCREENLOG; exit" TERM EXIT
+
+# if screen session does not exist, create it
+# remove screen logs to preserve slave_join logic
+( ps ax | grep SCREEN | grep piuparts-slave-screen >/dev/null) ||\
+    ( cd $SLAVEROOTDIR; screen -d -m -L -S piuparts-slave-screen; sleep 1; rm -f $SLAVEROOTDIR/screenlog.*)
+
+# make sure there is a window for this slave
+screen -S piuparts-slave-screen -X screen -L $SLAVENUM
 
-mkdir -p $SLAVEROOT
-cd $SLAVEROOT
+# launch the slave
+screen -S piuparts-slave-screen -p $SLAVENUM -X stuff "
+su - piupartss -c \"cd $SLAVEDIR; python /usr/share/piuparts/piuparts-slave\"
+"
 
-# finally, run piuparts-slave in screen
-screen -L -d -m -S $SESSIONNAME @sharedir@/piuparts/piuparts-slave
+trap - TERM EXIT
 
 echo "piuparts-slave has been started."

-- 
piuparts git repository



More information about the Piuparts-commits mailing list