Skip to content

Commit

Permalink
Ensure that info and fatal output always goes to stderr so not to con…
Browse files Browse the repository at this point in the history
…taminate stdout as well as ensure we get fatals even when output of cron is sent to /dev/null
  • Loading branch information
Richard Heelin committed May 22, 2015
1 parent dda362c commit c9a960c
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cronlock
Expand Up @@ -17,11 +17,11 @@

function info {
if [ "${CRONLOCK_VERBOSE}" = "yes" ]; then
echo "${1}"
echo "${1}" >&2
fi
}
function fatal {
echo "${1}"
echo "${1}" >&2
exit 201
}

Expand Down Expand Up @@ -69,10 +69,10 @@ function cmd {
until response=$(raw_cmd "${@}") || [[ $? != 1 && $? != 141 && $? != 142 ]]; do
# Connection either closed, errored or timed out
if [ $attempts -ge ${CRONLOCK_RECONNECT_ATTEMPTS} ]; then
fatal "Unable to reconnect to redis" >&2
fatal "Unable to reconnect to redis"
fi
sleep $(($attempts * ${CRONLOCK_RECONNECT_BACKOFF}))
info "Redis connection lost, reconnecting..." >&2
info "Redis connection lost, reconnecting..."
connect > /dev/null 2>&1
attempts=$(($attempts + 1))
done
Expand Down Expand Up @@ -106,7 +106,7 @@ function raw_cmd {
;;
*) # net yet handled
echo "ERR - Unknown response" >&2
info "${response}" >&2
info "${response}"
exit 201
;;
esac
Expand Down

0 comments on commit c9a960c

Please sign in to comment.