summaryrefslogtreecommitdiff
path: root/buildbot/checks.sh
blob: a53d005be4fee00db3636af6e706d8b525de5f9e (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/bin/bash

if test -z "${DEPLOYMENT}"; then
  echo Please provide DEPLOYMENT env var: 'test' or 'demo'
  exit 1
fi
DOMAIN="taler.net"

##
# Will stay as 'dummy' for 'demo' DEPLOYMENTs since we do
# want to get this value ignored and the active deployment
# to be checked.
NONACTIVE_COLOR="notneeded"

if test "test" = "${DEPLOYMENT}"; then
  NONACTIVE_COLOR="$(cat /home/test/nonactive)"
fi 

error_stringify ()
{
  case $1 in
    28) echo "connection timed out" ;;
     7) echo "failed to connect to host" ;;
     0) echo "successful" ;;
     *) echo "unknown, see curl man page" ;;
  esac
}

error_fmt="%s (http status code: %s)/(curl condition: %s - %s)\n"

URL="https://exchange.${DEPLOYMENT}.${DOMAIN}/"
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s "$URL" -o /dev/null \
  -w "%{http_code}")
if ! test 200 = $http_status_code; then
  printf "'%s' failed\n" $URL
  printf "$error_fmt" \
    "Exchange did not restart correctly" \
    $http_status_code $? "$(error_stringify $?)"
  exit 1
fi

URL="http://backend.${DEPLOYMENT}.${DOMAIN}/"
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s $URL \
  --header "Authorization: ApiKey sandbox" \
  -o /dev/null \
  -w "%{http_code}")
if ! test 200 = $http_status_code; then
  printf "'%s' failed\n" $URL
  printf "$error_fmt" \
    "Merchant backend did not restart correctly" \
    $http_status_code $? "$(error_stringify $?)"
  exit 1
fi


URL="https://shop.${DEPLOYMENT}.${DOMAIN}/"
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s $URL -o /dev/null \
  -w "%{http_code}")
if ! test 200 = $http_status_code; then
  printf "%s failed\n" $URL
  printf "$error_fmt" \
    "Blog did not restart correctly" \
    $http_status_code $? "$(error_stringify $?)"
  exit 1
fi

URL="https://survey.${DEPLOYMENT}.${DOMAIN}/"
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s $URL -o /dev/null \
  -w "%{http_code}")
if ! test 200 = $http_status_code; then
  printf "%s failed\n" $URL
  printf "$error_fmt" \
    "Survey site did not restart correctly" \
    $http_status_code $? "$(error_stringify $?)"
  exit 1
fi

URL="https://donations.${DEPLOYMENT}.${DOMAIN}/"
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s $URL -o /dev/null \
  -w "%{http_code}")
if ! test 200 = $http_status_code; then
  printf "%s failed\n" $URL
  printf "$error_fmt" \
    "Donations shop did not restart correctly" \
    $http_status_code $? "$(error_stringify $?)"
  exit 1
fi

URL="https://bank.${DEPLOYMENT}.${DOMAIN}/"
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s $URL -o /dev/null \
  -w "%{http_code}")
if ! test 302 = $http_status_code; then
  printf "%s failed\n" $URL
  printf "$error_fmt" \
    "Bank did not restart correctly" \
    $http_status_code $? "$(error_stringify $?)"
  exit 1
fi

URL="https://${DEPLOYMENT}.${DOMAIN}/en/index.html" 
http_status_code=$(curl \
  -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
  -s $URL -o /dev/null \
  -w "%{http_code}")
if ! test 200 = $http_status_code; then
  printf "%s failed\n" $URL
  printf "$error_fmt" \
    "Landing page not restart correctly" \
     $http_status_code $? "$(error_stringify $?)"
  exit 1
fi


if test "test" = ${DEPLOYMENT}; then
  URL="https://twister-backend.wild.gv.taler.net"
  http_status_code=$(curl \
    -H "X-Taler-Deployment-Color: ${NONACTIVE_COLOR}" \
    -H "Authorization: ApiKey sandbox" \
    -s $URL -o /dev/null \
    -w "%{http_code}")
  if ! test 200 = $http_status_code; then

    if test 503 = $http_status_code; then
      printf "%s %s\n" \
        "Hit a '503 Service Unavailable' from Twister." \
        "Assuming all is correct."
      exit 0
    fi

    # Real failure here.
    printf "%s failed\n" $URL
    printf "$error_fmt" \
      "Twister did not restart correctly" \
       $http_status_code $? "$(error_stringify $?)"
    exit 1

  fi
fi


printf "All services correctly restarted!\n"