Keep logging somewhat sane
We don't want an infinitely growing logfile. Instead we set a reasonable cap, currently 4MiB, and retain one backup.main
parent
12f12efb9b
commit
01295e851f
|
@ -3,11 +3,6 @@
|
||||||
#set -eux
|
#set -eux
|
||||||
|
|
||||||
LOG_FILE="/media/workshop/Projects/openmedianetwork/.omn_watchdog.log"
|
LOG_FILE="/media/workshop/Projects/openmedianetwork/.omn_watchdog.log"
|
||||||
touch ${LOG_FILE}
|
|
||||||
|
|
||||||
# Redirect all output to LOG_FILE but preserve a link to stdout should we
|
|
||||||
# still want to use it
|
|
||||||
exec 3>&1 1>>${LOG_FILE} 2>&1
|
|
||||||
|
|
||||||
RECIPIENTS=(
|
RECIPIENTS=(
|
||||||
saunders@openworlds.info
|
saunders@openworlds.info
|
||||||
|
@ -16,7 +11,7 @@ RECIPIENTS=(
|
||||||
|
|
||||||
URLS=(
|
URLS=(
|
||||||
unite.openworlds.info
|
unite.openworlds.info
|
||||||
openworlds.info
|
# NOTE: [Currently down] openworlds.info
|
||||||
pad.openworlds.info
|
pad.openworlds.info
|
||||||
visionon.tv
|
visionon.tv
|
||||||
activism.openworlds.info
|
activism.openworlds.info
|
||||||
|
@ -35,7 +30,22 @@ SERVICES=(
|
||||||
#mail.openworlds.info
|
#mail.openworlds.info
|
||||||
)
|
)
|
||||||
|
|
||||||
send_mail() {
|
rotate_log()
|
||||||
|
{
|
||||||
|
local -n log=$1
|
||||||
|
local max_log=4096 # 4M as we get size in K below
|
||||||
|
local log_size=$(du -k "${log}" | cut -f 1)
|
||||||
|
|
||||||
|
if ((${log_size} > ${max_log})); then
|
||||||
|
# Clobber any previous backup
|
||||||
|
mv -f ${log} ${log}.1
|
||||||
|
fi
|
||||||
|
|
||||||
|
touch ${log}
|
||||||
|
}
|
||||||
|
|
||||||
|
send_mail()
|
||||||
|
{
|
||||||
local -n error_list=$1
|
local -n error_list=$1
|
||||||
local error_string=""
|
local error_string=""
|
||||||
|
|
||||||
|
@ -48,13 +58,18 @@ send_mail() {
|
||||||
|
|
||||||
cat mail_template \
|
cat mail_template \
|
||||||
| sed "s/{ERR_LIST}/${error_string}/g" \
|
| sed "s/{ERR_LIST}/${error_string}/g" \
|
||||||
| msmtp -a omn_server_watch ${RECIPIENTS[@]} 2>/dev/null \
|
| msmtp -a omn_server_watch ${RECIPIENTS[@]} \
|
||||||
|| echo "[ERROR] Failed to send mail!"
|
|| echo "[ERROR] Failed to send mail!"
|
||||||
}
|
}
|
||||||
|
|
||||||
declare -A FLAGGED
|
declare -A FLAGGED
|
||||||
|
|
||||||
echo "== $(date)"
|
rotate_log LOG_FILE
|
||||||
|
# Redirect all output to LOG_FILE but preserve a link to stdout should we
|
||||||
|
# still want to use it
|
||||||
|
exec 3>&1 1>>${LOG_FILE} 2>&1
|
||||||
|
|
||||||
|
echo ">> $(date)"
|
||||||
echo "== Checking:"
|
echo "== Checking:"
|
||||||
|
|
||||||
for uri in "${URLS[@]}"; do \
|
for uri in "${URLS[@]}"; do \
|
||||||
|
|
Loading…
Reference in New Issue