-
Notifications
You must be signed in to change notification settings - Fork 0
/
cns-health.sh
executable file
·77 lines (64 loc) · 1.57 KB
/
cns-health.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash -x
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (c) 2016, Brian Bennett.
if [[ $(zonename) == global ]]; then
printf "This can only be used in non-global zones\n"
exit 1
fi
dirname="${0%/*}" # Same as $(dirname $0)
basename="${0##*/}" # Same as $(basename $0)
source /lib/svc/share/smf_include.sh
function check_health () {
result=0
for check in ${dirname}/check.d/*.sh; do
$check
result=$(( result + $? ))
done
if (( result == 0 )); then
enable_cns
else
disable_cns
fi
}
function set_cns_status () {
status=$(mdata-get triton.cns.status)
[[ ${status:up} == $1 ]] || mdata-put triton.cns.status "$1"
}
function disable_cns () {
set_cns_status down
}
function enable_cns () {
set_cns_status up
}
function method_start () {
while :; do
check_health
sleep 60
done
}
trap disable_cns EXIT
action=${*:OPTIND:1}
self=${*:OPTIND:2}
case $action in
start)
# Disable right off the bat, just in case we didn't go down cleanly
# e.g., in the event of a panic. This ensures that long health checks
# don't delay removal of broken services at boot.
disable_cns
method_start
;;
stop)
method_stop
;;
refresh)
exit 0
;;
*)
printf 'Action was %s\n' "$action"
exit "$SMF_EXIT_ERR_FATAL"
;;
esac
exit 0