@@ -44,6 +44,11 @@ RUN set -ex && \
|
||||
|
||||
EXPOSE 8125/udp 8092/udp 8094
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
COPY settings.sh /settings.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
CMD ["telegraf"]
|
||||
|
||||
# Labels
|
||||
LABEL \
|
||||
io.hass.name="${BUILD_NAME}" \
|
||||
|
||||
@@ -32,10 +32,8 @@ docker_api: true
|
||||
host_pid: true
|
||||
full_access: true
|
||||
options:
|
||||
configuration:
|
||||
custom_conf:
|
||||
location: "/config/telegraf.conf"
|
||||
log_level: info
|
||||
schema:
|
||||
configuration:
|
||||
custom_conf:
|
||||
location: str
|
||||
log_level: list(trace|debug|info|notice|warning|error|fatal)?
|
||||
17
telegraf/entrypoint.sh
Executable file
17
telegraf/entrypoint.sh
Executable file
@@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
bashio /settings.sh
|
||||
|
||||
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
|
||||
37
telegraf/rootfs/etc/conf-init.d/00-banner.sh
Executable file
37
telegraf/rootfs/etc/conf-init.d/00-banner.sh
Executable file
@@ -0,0 +1,37 @@
|
||||
#!/command/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Home Assistant Community Add-on: Base Images
|
||||
# Displays a simple add-on banner on startup
|
||||
# ==============================================================================
|
||||
if bashio::supervisor.ping; then
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue " Add-on: $(bashio::addon.name)"
|
||||
bashio::log.blue " $(bashio::addon.description)"
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
|
||||
bashio::log.blue " Add-on version: $(bashio::addon.version)"
|
||||
if bashio::var.true "$(bashio::addon.update_available)"; then
|
||||
bashio::log.magenta ' There is an update available for this add-on!'
|
||||
bashio::log.magenta \
|
||||
" Latest add-on version: $(bashio::addon.version_latest)"
|
||||
bashio::log.magenta ' Please consider upgrading as soon as possible.'
|
||||
else
|
||||
bashio::log.green ' You are running the latest version of this add-on.'
|
||||
fi
|
||||
|
||||
bashio::log.blue " System: $(bashio::info.operating_system)" \
|
||||
" ($(bashio::info.arch) / $(bashio::info.machine))"
|
||||
bashio::log.blue " Home Assistant Core: $(bashio::info.homeassistant)"
|
||||
bashio::log.blue " Home Assistant Supervisor: $(bashio::info.supervisor)"
|
||||
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
bashio::log.blue \
|
||||
' Please, share the above information when looking for help'
|
||||
bashio::log.blue \
|
||||
' or support in, e.g., GitHub, forums or the Discord chat.'
|
||||
bashio::log.blue \
|
||||
'-----------------------------------------------------------'
|
||||
fi
|
||||
46
telegraf/rootfs/etc/conf-init.d/01-log-level.sh
Executable file
46
telegraf/rootfs/etc/conf-init.d/01-log-level.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/command/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Home Assistant Community Add-on: Base Images
|
||||
# Sets the log level correctly
|
||||
# ==============================================================================
|
||||
declare log_level
|
||||
|
||||
# Check if the log level configuration option exists
|
||||
if bashio::config.exists log_level; then
|
||||
|
||||
# Find the matching LOG_LEVEL
|
||||
log_level=$(bashio::string.lower "$(bashio::config log_level)")
|
||||
case "${log_level}" in
|
||||
all)
|
||||
log_level="${__BASHIO_LOG_LEVEL_ALL}"
|
||||
;;
|
||||
trace)
|
||||
log_level="${__BASHIO_LOG_LEVEL_TRACE}"
|
||||
;;
|
||||
debug)
|
||||
log_level="${__BASHIO_LOG_LEVEL_DEBUG}"
|
||||
;;
|
||||
info)
|
||||
log_level="${__BASHIO_LOG_LEVEL_INFO}"
|
||||
;;
|
||||
notice)
|
||||
log_level="${__BASHIO_LOG_LEVEL_NOTICE}"
|
||||
;;
|
||||
warning)
|
||||
log_level="${__BASHIO_LOG_LEVEL_WARNING}"
|
||||
;;
|
||||
error)
|
||||
log_level="${__BASHIO_LOG_LEVEL_ERROR}"
|
||||
;;
|
||||
fatal)
|
||||
log_level="${__BASHIO_LOG_LEVEL_FATAL}"
|
||||
;;
|
||||
off)
|
||||
log_level="${__BASHIO_LOG_LEVEL_OFF}"
|
||||
;;
|
||||
*)
|
||||
bashio::exit.nok "Unknown log_level: ${log_level}"
|
||||
esac
|
||||
|
||||
bashio::log.blue "Log level is set to ${__BASHIO_LOG_LEVELS[$log_level]}"
|
||||
fi
|
||||
11
telegraf/rootfs/etc/conf-init.d/02-set-timezone.sh
Executable file
11
telegraf/rootfs/etc/conf-init.d/02-set-timezone.sh
Executable file
@@ -0,0 +1,11 @@
|
||||
#!/command/with-contenv bashio
|
||||
# ==============================================================================
|
||||
# Home Assistant Community Add-on: Base Images
|
||||
# Configures the timezone
|
||||
# ==============================================================================
|
||||
if ! bashio::var.is_empty "${TZ}"; then
|
||||
bashio::log.info "Configuring timezone"
|
||||
|
||||
ln --symbolic --no-dereference --force "/usr/share/zoneinfo/${TZ}" /etc/localtime
|
||||
echo "${TZ}" > /etc/timezone
|
||||
fi
|
||||
@@ -1,15 +0,0 @@
|
||||
#!/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"
|
||||
@@ -1,27 +0,0 @@
|
||||
#!/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
|
||||
13
telegraf/settings.sh
Executable file
13
telegraf/settings.sh
Executable file
@@ -0,0 +1,13 @@
|
||||
#!/usr/bin/env bashio
|
||||
declare hostname
|
||||
bashio::require.unprotected
|
||||
|
||||
readonly CONFIG="/etc/telegraf/telegraf.conf"
|
||||
|
||||
CUSTOM_CONF=$(bashio::config 'custom_conf.location')
|
||||
|
||||
bashio::log.info "Using custom conf file"
|
||||
rm /etc/telegraf/telegraf.conf
|
||||
cp "${CUSTOM_CONF}" /etc/telegraf/telegraf.conf
|
||||
|
||||
bashio::log.info "Finished updating config, Starting Telegraf"
|
||||
Reference in New Issue
Block a user