#!/bin/bash

if [ -z "$JICOFO_CPU" ]; then JICOFO_CPU=3; fi

JAVA_SYS_PROPS="-Dnet.java.sip.communicator.SC_HOME_DIR_LOCATION=/config \
		-Dnet.java.sip.communicator.SC_HOME_DIR_NAME=jicofo \
		-Djava.util.logging.config.file=/config/jicofo/logging.properties \
		-Djava.library.path=/usr/share/jicofo/lib/ \
		-Dru.yandex.rtc.applicationName=jicofo \
		-Dru.yandex.rtc.environment=${YANDEX_ENVIRONMENT} \
		-Dru.yandex.rtc.jicofo.grpc.ssl.crt=/config/jicofo/certs/ssl.crt \
		-Dru.yandex.rtc.jicofo.grpc.ssl.key=/config/jicofo/certs/ssl.key \
		-Dru.yandex.rtc.tvm.mediator.clientId=${JICOFO_MEDIATOR_CLIENT_ID:-2010990} \
		-Dru.yandex.rtc.mediator.host=${JICOFO_MEDIATOR_HOST} \
		-Dru.yandex.rtc.mediator.port=${JICOFO_MEDIATOR_PORT:-4992} \
		-Dru.yandex.rtc.tvm.self.clientId=${JICOFO_TVM_CLIENT_ID} \
		-Dru.yandex.rtc.tvm.self.clientSecret=${JICOFO_TVM_SECRET} \
		-XX:+PrintGCApplicationStoppedTime -XX:+PrintGCDateStamps \
		-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=10M \
		-Xloggc:/var/log/telemost/jicofo/jicofo.gc.log
		-XX:ActiveProcessorCount=$JICOFO_CPU
		-Dlog4j.formatMsgNoLookups=true
		-Dlog4j2.formatMsgNoLookups=true"

DAEMON=/usr/share/jicofo/jicofo.sh
DAEMON_DIR=/usr/share/jicofo/
DAEMON_OPTS="--domain=$XMPP_DOMAIN --host=localhost --secret=$JICOFO_COMPONENT_SECRET --user_name=focus --user_domain=auth.$XMPP_DOMAIN --user_password=$JICOFO_AUTH_PASSWORD"

exec /bin/bash -c "cd $DAEMON_DIR; JAVA_SYS_PROPS=\"$JAVA_SYS_PROPS\" exec $DAEMON $DAEMON_OPTS"
