-
Notifications
You must be signed in to change notification settings - Fork 0
/
health-check.sh
57 lines (49 loc) · 1.24 KB
/
health-check.sh
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
#!/bin/bash
#
# Health-check our services and restart them as needed
#
# Usage: {0} <service>
set -eo pipefail
KNOWN_SERVICES='service1, service2, service3'
function _info () { echo -e "[health] INFO - $*" 1>&2; }
function _warn () { echo -e "[health] WARN - $*" 1>&2; }
function check_health () {
_info "checking '$1'..."
curl -s --head "$1" | head -n1 | grep '200 OK' > /dev/nul || {
_warn "$1 appears to be down!"
return 1
}
_info "$1 appears to be up!"
}
function check_shop () {
check_health 'https://subdomain.domain.tld/' || {
_warn 'service1 is down. restarting!'
service shop restart
}
}
function check_service2 () {
check_health 'http://domain.tld/' || {
_warn 'service2 is down. restarting!'
service codoh restart
}
}
function service3 () {
check_health 'https://domain.tld/somepage.ext' || {
_warn 'service3 is down. restarting!'
service nginx restart
service php5-fpm restart
}
}
case "$1" in
service1) check_service1; ;;
service2) check_service2; ;;
service3) check_service3; ;;
'')
_warn "Missing required argument <service>."
_warn "Must be one of: $KNOWN_SERVICES"
;;
*)
_warn "unknown service: $1."
_warn "Must be one of: $KNOWN_SERVICES";
;;
esac