#!/bin/ksh

[[ -r /etc/jvb/jvb.in.sh ]] && . /etc/jvb/jvb.in.sh

: ${JVB_CONF:=/etc/jvb/jvb.conf}
: ${JVB_LOG_CONFIG:=/usr/local/share/jvb/lib/logging.properties}
: ${JVB_TRUSTSTORE:=/etc/ssl/jvb-key.store}
: ${JVB_TRUSTSTORE_PASSWORD:='CHANGE_ME'}
: ${JVB_MAXMEM:=3G}
: ${JVB_DHKEYSIZE:=2048}
: ${JVB_GC_TYPE:=G1GC}
: ${JVB_SC_HOME_LOCATION:=/etc}
: ${JVB_SC_HOME_NAME:=jvb}

JAVA=$(/usr/local/bin/javaPathHelper -c "jitsi-videobridge")
mainClass="org.jitsi.videobridge.MainKt"
cp="/usr/local/share/java/classes/jitsi-videobridge.jar"

exec ${JAVA} -Xmx${JVB_MAXMEM} -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp \
	-Dconfig.file=${JVB_CONF} \
	-Djava.util.logging.config.file=${JVB_LOG_CONFIG} \
	-Djdk.tls.ephemeralDHKeySize=${JVB_DHKEYSIZE} \
	-XX:+Use${JVB_GC_TYPE} \
	-Djavax.net.ssl.trustStore=${JVB_TRUSTSTORE} \
	-Djavax.net.ssl.trustStorePassword=${JVB_TRUSTSTORE_PASSWORD} \
	-Dnet.java.sip.communicator.SC_HOME_DIR_LOCATION=${JVB_SC_HOME_LOCATION} \
	-Dnet.java.sip.communicator.SC_HOME_DIR_NAME=${JVB_SC_HOME_NAME} \
	${JAVA_SYS_PROPS} \
	-cp ${cp} ${mainClass} ${@}
