This commit is contained in:
2023-08-27 17:33:05 +02:00
parent 798a8932af
commit a7c9ca3f2f
9 changed files with 46 additions and 131 deletions

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bashio
# ==============================================================================
# Take down the S6 supervision tree when telegraf fails
# s6-overlay docs: https://github.com/just-containers/s6-overlay
# ==============================================================================
declare APP_EXIT_CODE=${1}
if [[ "${APP_EXIT_CODE}" -ne 0 ]] && [[ "${APP_EXIT_CODE}" -ne 256 ]]; then
bashio::log.warning "Halt add-on with exit code ${APP_EXIT_CODE}"
echo "${APP_EXIT_CODE}" > /run/s6-linux-init-container-results/exitcode
exec /run/s6/basedir/bin/halt
fi
bashio::log.info "Service restart after closing"

View File

@@ -0,0 +1,27 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: telegraf
# Runs telegraf
# ==============================================================================
declare log_level
bashio::log.info 'Starting telegraf...'
bashio::require.unprotected
CONFIGURATION=$(bashio::config 'configuration.location')
bashio::log.info "Using configuration file ${CONFIGURATION}"
rm /etc/telegraf/telegraf.conf
cp "${CONFIGURATION}" /etc/telegraf/telegraf.conf
if [ "${1:0:1}" = '-' ]; then
set -- telegraf "$@"
fi
if [ $EUID -ne 0 ]; then
exec "$@"
else
# Allow telegraf to send ICMP packets and bind to privliged ports
setcap cap_net_raw,cap_net_bind_service+ep /usr/bin/telegraf || echo "Failed to set additional capabilities on /usr/bin/telegraf"
exec setpriv --reuid root --init-groups "$@"
fi