# OSGi runner config options
#
# $Id$

# JAVA_HOME: The java runtime to use under sysvinit, systemd strictly uses /usr/bin/java
#
# The standard is auto-detected from the symlink in /etc/alternatives
#
# If you want a specific java runtime, replace the auto-detection
# with a valid JRE/JDK installation directory.
#
# Be aware, that the init.d script checks, whether
#   $JAVA_HOME/bin/java or $JAVA_HOME/jre/bin/java
# exists.
#
# To change the default java in RHEL/CentOS call   alternatives --config java
#
# To change the default java in Debian call something like
#   update-java-alternatives --set java-1.8.0-openjdk-amd64
# or
#   update-java-alternatives --set java-1.11.0-openjdk-amd64
# 
JAVA_HOME=$(readlink /etc/alternatives/java |sed -e 's%/bin/java$%%' -e 's%/jre$%%')

# some environments (like eclipse-temurin) use a Java build that doesn't respect any /etc/alternatives/ system:
test -z "$JAVA_HOME" && JAVA_HOME=$(readlink -f $(which java) |sed -e 's%/bin/java$%%' -e 's%/jre$%%')


# OSGI_OPTS: Additional java options for starting osgi-runner.
OSGI_OPTS="-Dfile.encoding=utf-8 -Djava.awt.headless=true -Xms256m -Xmx1024m"

#
# uncomment this line, if you want a server-grade concurrent garbage collector
#
# Note: variable replacements are not supported by systemd, so add the needed
# options to the main OSGI_OPTS line above.
#
#OSGI_OPTS="${OSGI_OPTS} -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled"

#
# uncomment this line, if you want to connect to osgi-runner using the java remote debugger.
#
# Note: variable replacements are not supported by systemd, so add the needed
# options to the main OSGI_OPTS line above.
#
#OSGI_OPTS="${OSGI_OPTS} -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n"

#
# runtime user and group
#
# To overwrite the default from /usr/lib/systemd/system/osgi-runner.service
# create one or more files with service overrides in
#   /etc/systemd/system/osgi-runner.service.d
# i.e. 
#   /etc/systemd/system/osgi-runner.service.d/custom.conf
# with something like
#  [Service]
#  User=myosgiuser
#  Group=myosgigroup
#
# Do not forget to call
#   systemctl status osgi-runner
# to make systemd load those overwrites.
#

# admin user, should be member of OSGI_GROUP
OSGI_ADMIN=root

# chown directories besides the usual
CHOWN_DIRS=""

# chown mode for log directory, cache directory, deploy directory and CHOWN_DIRS 
CHOWN_MODE=770


# source eventual configs and preparation snippets from /etc/default/osgi-runner-extras* 
# from docker layer injections or addon-packages like osgi-runner-merging-bundle-activator
export OSGI_OPTS
ORELIST=$(find /etc/default/ -maxdepth 1 -type f -name 'osgi-runner-extras*' |grep -v "dpkg-" |sort)
if [ -z "$ORELIST" ] ; then
  echo '/etc/default/osgi-runner: No /etc/default/osgi-runner-extras* to source'
else
  for ORE in ${ORELIST} ; do
    #echo "DEBUG: OSGI_OPTS before ${ORE}: ${OSGI_OPTS}"
    echo "/etc/default/osgi-runner: Sourcing extras $ORE"
    . $ORE
    #echo "DEBUG: OSGI_OPTS after ${ORE}: ${OSGI_OPTS}"
  done
fi

