hassio-zabbix-agent2/rootfs/etc/services.d/zabbix-agent2/run

42 lines
1.1 KiB
Plaintext
Raw Normal View History

2022-06-13 07:14:07 +00:00
#!/usr/bin/with-contenv bashio
# ==============================================================================
# Start zabbix-agent2 service if enabled
# ==============================================================================
set -e
2022-06-13 09:07:20 +00:00
CONFIG_PATH=/data/options.json
2022-06-13 07:14:07 +00:00
CUSTOM_CFG_PATH=/share/zabbix-agent2
2022-06-13 09:07:20 +00:00
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)"
2022-06-13 07:14:07 +00:00
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}"