This commit is contained in:
2025-04-24 19:42:14 +03:00
parent 22cb685d90
commit 43acf825d7
15 changed files with 94 additions and 389 deletions

View File

@@ -0,0 +1,45 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Community Add-on: Vector
# ==============================================================================
declare exit_code
readonly exit_code_container=$(</run/s6-linux-init-container-results/exitcode)
readonly exit_code_service="${1}"
readonly exit_code_signal="${2}"
readonly service="zabvbix-agent2"
bashio::log.info \
"Service ${service} exited with code ${exit_code_service}" \
"(by signal ${exit_code_signal})"
# Received a signal
if [[ "${exit_code_service}" -eq 256 ]]; then
# The signal might be a result of another service crashing. Only
# overwrite the container exit code if it is not already set.
if [[ "${exit_code_container}" -eq 0 ]]; then
echo $((128 + $exit_code_signal)) > /run/s6-linux-init-container-results/exitcode
fi
# If the signal is SIGTERM, we should halt the container and take down
# the whole process tree.
[[ "${exit_code_signal}" -eq 15 ]] && exec /run/s6/basedir/bin/halt
# The service exited with a non-zero exit code, which means it crashed.
elif [[ "${exit_code_service}" -ne 0 ]]; then
# The service might be a result of another service crashing. Only
# overwrite the container exit code if it is not already set.
if [[ "${exit_code_container}" -eq 0 ]]; then
echo "${exit_code_service}" > /run/s6-linux-init-container-results/exitcode
fi
# We should halt the container and take down the whole process tree.
exec /run/s6/basedir/bin/halt
# The service exited with a zero exit code, which means it exited, let
# S6 supervision restart it.
else
bashio::log.info "Service ${service} restarting..."
fi

View File

@@ -0,0 +1,10 @@
#!/command/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Zabbix Agent2
# Runs zabbix_agent2
# ==============================================================================
bashio::log.info "Starting Zabbix Agent2..."
exec /usr/sbin/zabbix_agent2 -c /config/zabbix-agent2.conf --foreground

View File

@@ -0,0 +1 @@
longrun

View File

@@ -1,15 +0,0 @@
#!/usr/bin/env bashio
# ==============================================================================
# Take down the S6 supervision tree when zabbix agent 2 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

@@ -1,20 +0,0 @@
#!/usr/bin/with-contenv bashio
# shellcheck shell=bash
# ==============================================================================
# Home Assistant Add-on: Zabbix agent 2
# Runs zabbix agent 2
# ==============================================================================
declare -a options
readonly ZBX_CFG_FILE='/config/zabbix_agent2.conf'
bashio::log.info 'Starting zabbix-agent2...'
if ! bashio::fs.file_exists "${ZBX_CFG_FILE}" || [ -z "$(ls -A ${ZBX_CFG_FILE})" ]; then
bashio::log.info "No config ${ZBX_CFG_FILE} exists, copying default."
cp /etc/zabbix/zabbix_agent2.conf ${ZBX_CFG_FILE}
fi
options+=(--foreground)
options+=(-c /config/zabbix_agent2.conf)
exec zabbix_agent2 "${options[@]}"

View File

@@ -1,13 +0,0 @@
#!/usr/bin/with-contenv bashio
readonly ZBX_CFG_FILE='/config/zabbix_agent2.conf'
bashio::log.info 'Starting zabbix-agent2...'
if ! bashio::fs.file_exists "${ZBX_CFG_FILE}" || [ -z "$(ls -A ${ZBX_CFG_FILE})" ]; then
bashio::log.info "No config ${ZBX_CFG_FILE} exists, copying default."
cp /etc/zabbix/zabbix_agent2.conf ${ZBX_CFG_FILE}
fi
# Run zabbix-agent2 in foreground
# zabbix_agent2 --foreground -c /config/zabbix_agent2.conf
exec /etc/services.d/zabbix_agent2/run