# svc-runner config options

# 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 Debian call something like
#   update-java-alternatives --set temurin-21-jdk-amd64
#
JAVA_HOME=$(readlink /etc/alternatives/java |sed -e 's%/bin/java$%%' -e 's%/jre$%%')

#
# Configuration directory, should only be changed in exceptional
# setups.
#
# This option is ignored in docker environments.
#
SVCRUNNER_ETC=/etc/svc-runner

# 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$%%')


# SVCRUNNER_OPTS: Additional java options for starting svc-runner.

#
# Additional modules to be activated on the boot layer.
#
SVCRUNNER_OPTS="--add-modules com.fasterxml.jackson.dataformat.cbor,java.sql,jakarta.servlet,java.scripting,jdk.net,java.net.http,org.apache.commons.cli"

#
# Memory and the like
#
SVCRUNNER_OPTS="${SVCRUNNER_OPTS} -Dfile.encoding=utf-8 -Djava.awt.headless=true -Xms${SVCRUNNER_XMS:-256m} -Xmx${SVCRUNNER_XMX:-1024m}"

#
# HTTP client log level.
#
test -z "$SVCRUNNER_HTTPCLIENT_LOG" && SVCRUNNER_HTTPCLIENT_LOG=errors,requests

SVCRUNNER_OPTS="${SVCRUNNER_OPTS} -Djdk.httpclient.HttpClient.log=${SVCRUNNER_HTTPCLIENT_LOG}"

#
# 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 SVCRUNNER_OPTS line above.
#
#SVCRUNNER_OPTS="${SVCRUNNER_OPTS} -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled"

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

#
# The logback configuration file in /etc/svc-runner/logging.d to load.
#
test -z "$SVCRUNNER_LOGBACK_XML" && SVCRUNNER_LOGBACK_XML=logback-stdout.xml

#
# runtime user and group
#
# To overwrite the default from /usr/lib/systemd/system/svc-runner.service
# create one or more files with service overrides in
#   /etc/systemd/system/svc-runner.service.d
# i.e.
#   /etc/systemd/system/svc-runner.service.d/custom.conf
# with something like
#  [Service]
#  User=mysvcrunneruser
#  Group=mysvcrunnergroup
#
# Do not forget to call
#   systemctl status svc-runner
# to make systemd load those overwrites.
#
# In docker environments, the uid/gid is simply determined from the running process.
#

SVCRUNNER_USER=$(test -x /usr/bin/systemctl && /usr/bin/systemctl show svc-runner.service -P User || id -u)
SVCRUNNER_GROUP=$(test -x /usr/bin/systemctl && /usr/bin/systemctl show svc-runner.service -P Group || id -g)

# admin user, should be member of SVCRUNNER_GROUP
SVCRUNNER_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/svc-runner-extras*
# from docker layer injections or addon-packages like svc-runner-merging-bundle-activator
export SVCRUNNER_OPTS
SRELIST=$(find /etc/default/ -maxdepth 1 -type f -name 'svc-runner-extras*' |grep -v "dpkg-" |sort)
if [ -z "$SRELIST" ] ; then
  echo '/etc/default/svc-runner: No /etc/default/svc-runner-extras* to source' 1>&2
else
  for SRE in ${SRELIST} ; do
    #echo "DEBUG: SVCRUNNER_OPTS before ${SRE}: ${SVCRUNNER_OPTS}"
    echo "/etc/default/svc-runner: Sourcing extras $SRE" 1>&2
    . $SRE
    #echo "DEBUG: SVCRUNNER_OPTS after ${SRE}: ${SVCRUNNER_OPTS}"
  done
fi


