~vcs-imports/dehs/trunk

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash

set -e


export BASEDIR=/org/home/groups/dehs
export WORKDIR=$BASEDIR/dehs_prj/dehs

PATH="$BASEDIR/bin:$PATH"
LOCK=$BASEDIR/run.lock
BNAME=$(basename "$0")

attempts=0
maxattempts=30

while true; do
    if ! ln -s $$ $LOCK &>/dev/null; then
        PID=$(basename $(readlink -f $LOCK))
        if [ ! -n "$PID" ] || ! ps -p "$PID" | grep "$BNAME" &>/dev/null; then
            echo "Removing stale lock file"
            rm $LOCK
        else
            if [ $attempts -eq $maxattempts ]; then
                echo "Max number of attempts ($maxattempts) to run reached, surrending to a forever running instance" >&2
                exit 1
            fi
            # lock file is okay, dehs.sh running
            # let's wait ten minutes and try again
            sleep $((10 * 60)) || exit 1
            ((attempts++))
        fi
    else
        break
    fi
done

run_type="-update_all"
update_www=1

if [ ! -z "$1" ]; then
    case $1 in
        all)
                run_type="-update_all"
        ;;
        new)
                run_type="-update_new"
        ;;
        bogus)
                run_type="-update_bogus"
        ;;
        wwiz)
                run_type="-wwiz"
        ;;
        popcon)
                run_type="-dl_popcon -db_popcon"
        ;;
        bugs)
                run_type="-db_up_error"
                update_www=0
        ;;
        db)
                run_type="-dehsqa_db"
                update_www=0
        ;;
	www)
		run_type=
	;;
        *)
                echo "Unknown run-type: $1" >&2
                exit 1
        ;;
    esac
fi

for rt in $run_type; do
	$WORKDIR/dehs_pg.php $rt >$WORKDIR/logs/stdout.log
done

c=0
if [ $update_www -gt 0 ]; then
	while ! $WORKDIR/update_wwwal.sh >/dev/null && [ $c -lt 50 ]; do
		sleep 5
		((c++))
	done
fi

rm $LOCK