~chromium-team/chromium-browser/artful-beta

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/sh

# Simple keep-alive script echoing the date on stdout
# This is needed to prevent the builders from killing a build
# staying too long without producing outputs, like while
# linking chromium with ld-bfd.
#
# Usage:
#    keep-alive.sh start &
#    some actions...
#    keep-alive.sh stop
#
# Authors:
#  Fabien Tassin <fta@sofaraway.org>
# License: GPLv2 or later

ACTION=$1
LOCK=/var/tmp/k-a.lock
INTERVAL=5
LINTERVAL=300

case $ACTION in
 start)
   echo $$ > $LOCK
   T0=$(date +%s)
   T1=0
   while [ 1 ] ; do
     if [ ! -f $LOCK ] ; then
       break
     fi
     T2=$(date +%s)
     if [ $((T2-T1)) -ge $LINTERVAL ] ; then
       DELTA=$((T2-T0))
       FREE=$(free -mo | cut -c1-6,30-40 | tail -2 | awk '{ print "Free " $1 " " $2 "M" } ' | tr '\n' ' ')
       echo "[keep-alive] $(date) ($((DELTA/60)) min) [ $FREE]"
       T1=$T2
     fi
     sleep $INTERVAL || break
   done
   exit 0
   ;;
 stop)
   PID=$(cat $LOCK)
   rm -f $LOCK
   exit 0
   ;;
 *)
   echo "Usage: $(basename $0) [start|stop]"
   exit 1
esac