3 export SGMONDIR="$(dirname "$(realpath -- "$0")")"
5 [ -z "$1" ] && SGMONSRV="$(basename "$PWD")" || SGMONSRV="$1"
8 export SGMONTMP=`TMPDIR=/tmp/sgmon mktemp -d -t sgmon`
11 trap "rm -fr state $SGMONTMP" HUP PIPE INT QUIT TERM EXIT
14 [ -s max-attempts ] && read max_attempts < max-attempts || max_attempts=$ATTEMPTS_DEFAULT
15 [ -s state/attempts ] && read attempts < state/attempts || attempts=0
16 [ -x run ] && cmd=./run || cmd="sh -e run"
17 if $cmd >state/stdout 2>state/stderr ; then
18 if [ "$attempts" -ge "$max_attempts" ] ; then
19 "$SGMONDIR"/notify-ok.sh
26 attempts=$(( $attempts + 1 ))
27 echo $attempts > state/attempts
28 echo BAD ${attempts}/${max_attempts}
29 if [ $attempts -eq $max_attempts ] ; then
30 "$SGMONDIR"/notify-bad.sh
33 [ -s period ] && read period < period || period=$PERIOD_DEFAULT