summaryrefslogtreecommitdiffstats
path: root/mirroring/test-mirrors.sh
blob: 280118bc84541c482ec8f9eb41077ce62fecc5ae (plain)
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
#!/usr/bin/env bash
#
# Simple script which performs a HTTP and rsync check on
# all Ceph mirrors over IPv4 and IPv6 to see if they are online
#
# Requires IPv4, IPv6, rsync and curl
#
# Example usage:
# - ./test-mirrors.sh eu.ceph.com,de.ceph.com,hk.ceph.com
# - cat MIRRORS |cut -d ':' -f 1|xargs -n 1 ./test-mirrors.sh
#

function print_usage {
    echo "Usage: $0 mirror1,mirror2,mirror3,mirror4,etc"
}

function test_http {
    HOST=$1

    echo -n "$HOST HTTP IPv4: "
    curl -s -I -4 -o /dev/null http://$HOST
    if [ "$?" -ne 0 ]; then
        echo "FAIL"
    else
        echo "OK"
    fi

    echo -n "$HOST HTTP IPv6: "
    curl -s -I -6 -o /dev/null http://$HOST
    if [ "$?" -ne 0 ]; then
        echo "FAIL"
    else
        echo "OK"
    fi
}

function test_rsync {
    HOST=$1

    echo -n "$HOST RSYNC IPv4: "
    rsync -4 -avrqn ${HOST}::ceph /tmp 2>/dev/null
    if [ "$?" -ne 0 ]; then
        echo "FAIL"
    else
        echo "OK"
    fi

    echo -n "$HOST RSYNC IPv6: "
    rsync -6 -avrqn ${HOST}::ceph /tmp 2>/dev/null
    if [ "$?" -ne 0 ]; then
        echo "FAIL"
    else
        echo "OK"
    fi
}

MIRRORS=$1

if [ -z "$MIRRORS" ]; then
    print_usage
    exit 1
fi

IFS=', ' read -r -a array <<< "$MIRRORS"

for MIRROR in "${array[@]}"; do
    test_http $MIRROR
    test_rsync $MIRROR
done