Created
December 7, 2020 23:08
-
-
Save pirogoeth/6952ab3eafa482ddbd3c80641e1fb8e8 to your computer and use it in GitHub Desktop.
systemd notify-compatible wrapper script to launch and monitor filebeat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
CONNECT_TIMEOUT=${HTTP_CONNECT_TIMEOUT:-1} | |
HTTP_ADDR=${FILEBEAT_HTTP_ADDR:-http://localhost:5066/} | |
REPORT_TIME=$(($WATCHDOG_USEC / 2000000)) | |
SD_NOTIFY=${SD_NOTIFY_PATH:-/bin/systemd-notify} | |
set -euo pipefail | |
function watchdog() { | |
READY=0 | |
sleep ${REPORT_TIME} | |
while true ; do | |
info=$(curl -fs --connect-timeout "${CONNECT_TIMEOUT}" "${HTTP_ADDR}") | |
beat=$(echo "${info}" | jq -r .beat) | |
version=$(echo "${info}" | jq -r .version) | |
if [[ $? == 0 ]] ; then | |
if [[ $READY == 0 ]] ; then | |
"${SD_NOTIFY}" --ready | |
READY=1 | |
fi | |
"${SD_NOTIFY}" WATCHDOG=1 | |
"${SD_NOTIFY}" STATUS="${beat} running v${version}" | |
else | |
"${SD_NOTIFY}" WATCHDOG=trigger | |
"${SD_NOTIFY}" STATUS=Beat not responding | |
exit 1 | |
fi | |
sleep ${REPORT_TIME} | |
done | |
} | |
watchdog & | |
exec /usr/share/filebeat/bin/filebeat "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment