
JAVA=${JAVA:-"/usr/bin/java"}

JAVA_OPTIONS="-server $JAVA_OPTIONS"
JAVA_OPTIONS="$JAVA_OPTIONS -Dlogback.configurationFile=$ZABBIX_CONF_DIR/zabbix_java_gateway_logback.xml"

cd /usr/sbin/zabbix_java

CLASSPATH="lib"
for jar in `find lib bin ext_lib -name "*.jar"`; do
    CLASSPATH="$CLASSPATH:$jar"
done

if [ -n "$ZBX_LISTEN_IP" ]; then
    ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenIP=$ZBX_LISTEN_IP"
fi
if [ -n "$ZBX_LISTEN_PORT" ]; then
    ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.listenPort=$ZBX_LISTEN_PORT"
fi
if [ -n "$ZBX_START_POLLERS" ]; then
    ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.startPollers=$ZBX_START_POLLERS"
fi
if [ -n "$ZBX_TIMEOUT" ]; then
    ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.timeout=$ZBX_TIMEOUT"
fi
if [ -n "$ZBX_PROPERTIES_FILE" ]; then
    ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dzabbix.propertiesFile=$ZBX_PROPERTIES_FILE"
fi

tcp_timeout=${ZBX_TIMEOUT:=3}000
ZABBIX_OPTIONS="$ZABBIX_OPTIONS -Dsun.rmi.transport.tcp.responseTimeout=$tcp_timeout"

COMMAND_LINE="$JAVA $JAVA_OPTIONS -classpath $CLASSPATH $ZABBIX_OPTIONS com.zabbix.gateway.JavaGateway"

exec $COMMAND_LINE
