#!/usr/bin/with-contenv bashio # ============================================================================== # Start zabbix-agent2 service if enabled # ============================================================================== set -e CONFIG_PATH=/data/options.json CUSTOM_CFG_PATH=/share/zabbix-agent2 SERVER_OLD=$(jq --raw-output ".server" $CONFIG_PATH) SERVER="$(bashio::config 'server' $SERVER_OLD)" HOSTNAME_OLD=$(jq --raw-output ".hostname" $CONFIG_PATH) HOSTNAME="$(bashio::config 'hostname' $HOSTNAME_OLD)" if [ ! -d "$CUSTOM_CFG_PATH" ] ; then bashio::log.info "Creating a folder for custom configuration" mkdir -p "$CUSTOM_CFG_PATH" fi echo " Server=$SERVER ServerActive=$SERVER Hostname=$HOSTNAME LogType=console PidFile=/var/run/zabbix/zabbix_agent2.pid Include=${CUSTOM_CFG_PATH}/*.conf " > /etc/zabbix/zabbix_agent2.conf bashio::log.info "Starting zabbix-agent2" sudo -u zabbix zabbix_agent2 -f & AGENT_PID=$! # Register stop function stop_agent() { killall zabbix_agent2 exit 0 } trap "stop_agent" SIGTERM SIGHUP wait "${AGENT_PID}"