diff --git a/zabbix-agent2/Dockerfile b/zabbix-agent2/Dockerfile index ed85d2d..b5dbb78 100644 --- a/zabbix-agent2/Dockerfile +++ b/zabbix-agent2/Dockerfile @@ -1,15 +1,27 @@ -ARG BUILD_FROM=ghcr.io/hassio-addons/debian-base/amd64 -ARG BUILD_ARCH=amd64 +ARG BUILD_ARCH +ARG BUILD_VERSION +ARG BUILD_BASE_IMAGE=zabbix/zabbix-agent2:alpine-trunk -FROM ${BUILD_FROM} +FROM ${BUILD_BASE_IMAGE} as builder -RUN apk update && apk add --no-cache wget dpkg -RUN wget https://repo.zabbix.com/zabbix/6.5/debian/pool/main/z/zabbix-release/zabbix-release_6.5-1+debian12_all.deb && dpkg -i zabbix-release_6.5-1+debian12_all.deb +FROM alpine -RUN apk update && apk add --no-cache zabbix-agent2 +LABEL maintainer "Philipp Schmitt " -RUN mkdir /etc/services.d/zabbix-agent2 -COPY run /etc/services.d/zabbix-agent2/run -RUN chmod a+x /etc/services.d/zabbix-agent2/run +ENV LANG C.UTF-8 -CMD ["/etc/services.d/zabbix-agent2/run"] \ No newline at end of file +# Install requirements for add-on +# RUN apk add --no-cache jq zabbix-agent2 && \ +# addgroup -g 1003 docker && \ +# addgroup zabbix docker && \ +# mkdir -p /etc/zabbix/zabbix_agent2.d/plugins.d + +# Copy zabbix-agent2 plugins +COPY --from=builder ["/usr/sbin/zabbix-agent2-plugin", "/usr/sbin/zabbix-agent2-plugin"] +RUN echo -e "\nPlugins.PostgreSQL.System.Path=/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-mongodb\nPlugins.PostgreSQL.System.Path=/usr/sbin/zabbix-agent2-plugin/zabbix-agent2-plugin-postgresql\n" >> /etc/zabbix/zabbix_agent2.conf + +# Copy data for add-on +COPY run.sh / +RUN chmod a+x /run.sh + +CMD [ "/run.sh" ] \ No newline at end of file diff --git a/zabbix-agent2/run b/zabbix-agent2/run deleted file mode 100644 index 867c4c8..0000000 --- a/zabbix-agent2/run +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/with-contenv bashio -# shellcheck shell=bash -# ============================================================================== -# Home Assistant Add-on: Zabbix Agent2 -# Runs Zabbix Agent2 -# ============================================================================== - -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 - -/usr/sbin/zabbix_agent2 -c /config/zabbix_agent2.conf diff --git a/zabbix-agent2/run.sh b/zabbix-agent2/run.sh new file mode 100644 index 0000000..4de409e --- /dev/null +++ b/zabbix-agent2/run.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env ash +# shellcheck shell=dash + +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 +exec su zabbix -s /bin/ash -c "zabbix_agent2 -f -c /config/zabbix_agent2.conf" \ No newline at end of file