[Piuparts-commits] [SCM] piuparts git repository branch, piatti, updated. 0.49-105-gac1319a

Andreas Beckmann anbe at debian.org
Fri Mar 1 15:32:50 UTC 2013


The following commit has been merged in the piatti branch:
commit 9b46f1714841b5d780deb4a6ebbb7fd2f42e0505
Author: Andreas Beckmann <anbe at debian.org>
Date:   Sun Feb 10 00:04:53 2013 +0100

    slave-bin: factor out a file_age function
    
    for getting the age of a file in seconds
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>

diff --git a/slave-bin/detect_leftover_processes b/slave-bin/detect_leftover_processes
index 52672e0..6456a29 100755
--- a/slave-bin/detect_leftover_processes
+++ b/slave-bin/detect_leftover_processes
@@ -41,6 +41,16 @@ get_config_value()
 	eval "$1"='"$value"'
 }
 
+# outputs file age in seconds (or 0 if the file does not exist)
+file_age()
+{
+	local ctime now
+	test -e "$1" || echo "0"
+	ctime=$(stat -c %Z "$1" 2>/dev/null || echo 0)
+	now=$(date +%s)
+	echo $(($now - $ctime))
+}
+
 get_config_value SLAVEROOT global slave-directory
 get_config_value PIUPARTS_TMPDIR global tmpdir /org/piuparts.debian.org/tmp
 
@@ -48,10 +58,7 @@ get_config_value PIUPARTS_TMPDIR global tmpdir /org/piuparts.debian.org/tmp
 STATEFILE=$SLAVEROOT/leftover_processes
 
 # clear the statefile daily and whine again
-stamptime=$(stat -c %Z $STATEFILE 2>/dev/null || echo 0)
-unixtime=$(date +%s)
-difference=$(( $unixtime - $stamptime ))
-test $difference -lt 86000 || rm -f $STATEFILE
+test $(file_age $STATEFILE) -lt 86000 || rm -f $STATEFILE
 
 OUTPUT="$(sudo ls --color=never -lad /proc/*/root 2>/dev/null | grep "$PIUPARTS_TMPDIR" | grep "(deleted)")"
 if [ -z "$OUTPUT" ]; then
diff --git a/slave-bin/detect_slave_problems b/slave-bin/detect_slave_problems
index f0caa97..3349007 100755
--- a/slave-bin/detect_slave_problems
+++ b/slave-bin/detect_slave_problems
@@ -42,6 +42,16 @@ get_config_value()
 	eval "$1"='"$value"'
 }
 
+# outputs file age in seconds (or 0 if the file does not exist)
+file_age()
+{
+	local ctime now
+	test -e "$1" || echo "0"
+	ctime=$(stat -c %Z "$1" 2>/dev/null || echo 0)
+	now=$(date +%s)
+	echo $(($now - $ctime))
+}
+
 
 HOSTNAME=`hostname`
 if [ "$HOSTNAME" != "piatti" ] ; then
@@ -61,9 +71,7 @@ cd $MONITORDIR
 chown piupartsm:piuparts $MONITORDIR
 chmod 775 $MONITORDIR
 
-stamptime=$(/usr/bin/stat -c %Z $SCREENLOG 2>/dev/null || echo 0)
-unixtime=$(date +%s)
-difference=$(( $unixtime - $stamptime ))
+difference=$(file_age $SCREENLOG)
 
 # dont complain, if already complained and screenlog is younger than 31 min (=1800 sec) - the slave likes to sleep that long
 # FIXME: parse config file for duration...

-- 
piuparts git repository



More information about the Piuparts-commits mailing list