File: check

package info (click to toggle)
wbox 5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 244 kB
  • sloc: ansic: 2,428; sh: 36; makefile: 19
file content (51 lines) | stat: -rwxr-xr-x 973 bytes parent folder | download | duplicates (2)
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
#!/bin/sh

# not used `set -e' because some commands can fail

STATUS_ERROR=1
STATUS_SKIP=77

check_apache() {
    netstat --tcp -ln | grep 80

    if [ "$?" != 0 ]; then
        echo "apache2 is not listening at port TCP/80"
        echo "ending $0 with status $STATUS_SKIP"
        exit $STATUS_SKIP
    fi
}

check_wget_request() {
    wget -q -O /dev/null -4 localhost:80

    if [ "$?" != 0 ]; then
        echo "wget on localhost:80 failed"
        echo "ending $0 with status $STATUS_SKIP"
        exit $STATUS_SKIP
    fi
}

run_wbox() {
    MAXTRY=5
    itry=0

    while [ $itry -lt $MAXTRY ]; do
        wbox localhost 1 | grep "1 replies received" && break
        itry=`expr $itry + 1`

        sleep 1
    done

    if [ "$itry" -eq "$MAXTRY" ]; then
        echo "wbox query on localhost:80 failed $MAXTRY times"
        echo "ending $0 with status $STATUS_ERROR"
        exit $STATUS_ERROR
    fi
}

## main
check_apache
check_wget_request
run_wbox

exit 0