Kaynağa Gözat

Use links to /dev/null when logs are turned off

pull/33/head
Kristijan Mitrovic 4 yıl önce
ebeveyn
işleme
b491fdc8b9
1 değiştirilmiş dosya ile 13 ekleme ve 67 silme
  1. +13
    -67
      bubble-server/src/main/resources/packer/roles/bubble/files/log_manager.sh

+ 13
- 67
bubble-server/src/main/resources/packer/roles/bubble/files/log_manager.sh Dosyayı Görüntüle

@@ -4,77 +4,23 @@
# https://getbubblenow.com/bubble-license/
#

function die {
echo 1>&2 "${1}"
exit 1
}

BUBBLE_LOGS_FOLDER=/var/log/bubble
REDIS_LOG_FLAG_KEY="bubble.StandardSelfNodeService.bubble_server_logs_enabled"

SUPERVISOR_CONFIG_DIR=/etc/supervisor/conf.d
if [[ ! -d "${SUPERVISOR_CONFIG_DIR}" ]]; then
die "Cannot find folder with supervisor configuration files"
fi

# use bubble configuration as reference for current (previous) log flag state:
SUPERVISOR_BUBBLE_CONFIG=${SUPERVISOR_CONFIG_DIR}/bubble.conf
if [[ ! -f "${SUPERVISOR_BUBBLE_CONFIG}" ]]; then
die "Cannot find file with supervisor configuration for bubble process"
fi

BUBBLE_ERR_LOG=$(awk -F "=" '/stderr_logfile/ {print $2}' ${SUPERVISOR_BUBBLE_CONFIG} | xargs echo)
SUPERVISOR_LOG_FLAG=$([[ ${BUBBLE_ERR_LOG} != NONE* ]] && echo true || echo false)

REDIS_LOG_FLAG_VALUE=$(echo "get ${REDIS_LOG_FLAG_KEY}" | redis-cli | xargs echo | tr '[:upper:]' '[:lower:]')
REDIS_LOG_FLAG=$([[ ${REDIS_LOG_FLAG_VALUE} == true ]] && echo true || echo false)


function setLoggingForSupervisorConfig {
cfgFile="${1}"
logFlag="${2}"
tmpFile="$(mktemp /tmp/bubble.log_manager.XXXXXX)"

while IFS= read -r line; do
if [[ ${line} == std???_logfile* ]]; then
if [[ "${logFlag}" == "true" ]]; then
# the line should be `std???_logfile = NONE # <original value>` so just remove `NONE #`
echo "${line/_logfile = NONE # /_logfile = }" >> "${tmpFile}"
else
# truncate current log files:
logFile=$(echo "${line}" | awk -F "=" '{print $2}' | xargs echo)
# note that current log file will be truncated afterwards at the very end of this shell script together with
# other logs from this same folder (the log should be in ${BUBBLE_LOGS_FOLDER}).
# remove old logs if any:
rm "${logFile}.*"
# finally, set NONE got log output in supervisor config file's line:
if [[ ${line} != *"_logfile = NONE # "* ]]; then
# avoid adding multiple NONE in the line just in case with above test
echo "${line/_logfile = /_logfile = NONE # }" >> "${tmpFile}"
else
echo "${line}" >> "${tmpFile}"
fi
fi
else
echo "${line}" >> "${tmpFile}"
fi
done < "${cfgFile}"
cat "${tmpFile}" > "${cfgFile}"

rm "${tmpFile}"
}


if [[ "${SUPERVISOR_LOG_FLAG}" != "${REDIS_LOG_FLAG}" ]]; then
# change log setup on supervisor configs to match value from redis
for cfgFile in "${SUPERVISOR_CONFIG_DIR}"/* ; do
setLoggingForSupervisorConfig "${cfgFile}" "${REDIS_LOG_FLAG}"
if [[ ${REDIS_LOG_FLAG_VALUE} == true ]]; then
is_reload_needed=false
for logFile in $(find "${BUBBLE_LOGS_FOLDER}"/* -type l); do
rm "${logFile}"
touch "${logFile}"
is_reload_needed=true
done
if [[ ${is_reload_needed} == true ]]; then
supervisorctl reload
fi
else
for logFile in $(find "${BUBBLE_LOGS_FOLDER}"/* -type f); do
ln -sf /dev/null "${logFile}"
done
supervisorctl reread
supervisorctl reload
fi

if [[ "${REDIS_LOG_FLAG}" != "true" ]]; then
# truncate tmp bubble log files each time as those might have some output in between:
ls ${BUBBLE_LOGS_FOLDER}/* | xargs truncate -c -s0
fi

Yükleniyor…
İptal
Kaydet