Skip to content

Instantly share code, notes, and snippets.

@pirogoeth
Created December 7, 2020 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirogoeth/6952ab3eafa482ddbd3c80641e1fb8e8 to your computer and use it in GitHub Desktop.
Save pirogoeth/6952ab3eafa482ddbd3c80641e1fb8e8 to your computer and use it in GitHub Desktop.
systemd notify-compatible wrapper script to launch and monitor filebeat
#!/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