39 lines
907 B
Plaintext
39 lines
907 B
Plaintext
|
#!/usr/bin/with-contenv bashio
|
||
|
# ==============================================================================
|
||
|
# Start zabbix-agent2 service if enabled
|
||
|
# ==============================================================================
|
||
|
|
||
|
set -e
|
||
|
|
||
|
CUSTOM_CFG_PATH=/share/zabbix-agent2
|
||
|
|
||
|
SERVER="$(bashio::config 'server')"
|
||
|
HOSTNAME="$(bashio::config 'hostname')"
|
||
|
|
||
|
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}"
|