#!/bin/ash
GERRIT_DAEMON_OPTS="--console-log --enable-httpd"

IS_REPLICA=$(git config -f /var/gerrit/etc/gerrit.config --get container.replica)
if [[ "$IS_REPLICA" == "true" ]]; then
  GERRIT_DAEMON_OPTS="$GERRIT_DAEMON_OPTS --replica"
fi

JAVA_OPTIONS=$(git config --file /var/gerrit/etc/gerrit.config --get-all container.javaOptions)
JAVA_OPTIONS="$JAVA_OPTIONS -Dgerrit.instanceId=$POD_NAME"
java ${JAVA_OPTIONS} -jar /var/gerrit/bin/gerrit.war daemon \
  -d /var/gerrit \
  $GERRIT_DAEMON_OPTS
