#!/bin/sh
#
#    Licensed to the Apache Software Foundation (ASF) under one or more
#    contributor license agreements.  See the NOTICE file distributed with
#    this work for additional information regarding copyright ownership.
#    The ASF licenses this file to You under the Apache License, Version 2.0
#    (the "License"); you may not use this file except in compliance with
#    the License.  You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS,
#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#    See the License for the specific language governing permissions and
#    limitations under the License.
#

#
# handle specific scripts; the SCRIPT_NAME is exactly the name of the Karaf
# script: client, instance, shell, start, status, stop, karaf
#
# if [ "$KARAF_SCRIPT" == "SCRIPT_NAME" ]; then
#   Actions go here...
# fi

#
# general settings which should be applied for all scripts go here; please keep
# in mind that it is possible that scripts might be executed more than once, e.g.
# in example of the start script where the start script is executed first and the
# karaf script afterwards.
#

#
# The following section shows the possible configuration options for the default
# karaf scripts
#
# The settings below are designed to be overridden by the environment (for
# example, Docker container environment variables). Defaults are only applied
# when a value has NOT already been provided externally, and operator-supplied
# JVM flags are appended to the distribution defaults rather than replacing them.
#
# Variables an operator may set in the environment:
#   JAVA_MIN_MEM      Minimum heap (-Xms). Default: 512M
#   JAVA_MAX_MEM      Maximum heap (-Xmx). Default: 1024M
#   JAVA_OPTS         Extra generic JVM options; appended after the memory flags
#   EXTRA_JAVA_OPTS   Additional JVM options; appended after the defaults below
# Note: for a duplicated raw flag (e.g. two -Xmx), the JVM uses the LAST one,
# so externally-supplied flags (appended later) take precedence.
#
# export JAVA_HOME # Location of Java installation

# Apply memory defaults only when not already set in the environment.
: "${JAVA_MIN_MEM:=512M}" # Minimum memory for the JVM
: "${JAVA_MAX_MEM:=1024M}" # Maximum memory for the JVM
export JAVA_MIN_MEM JAVA_MAX_MEM

# Build JAVA_OPTS from the (possibly overridden) memory settings, preserving any
# JAVA_OPTS already provided externally. Memory flags come first so that a raw
# -Xms/-Xmx supplied via JAVA_OPTS still wins (last-flag-wins).
export JAVA_OPTS="-Xms${JAVA_MIN_MEM} -Xmx${JAVA_MAX_MEM} ${JAVA_OPTS}"

# export JAVA_NON_DEBUG_OPTS # Additional non-debug JVM options

# Keep the distribution's required defaults and append any externally-provided
# EXTRA_JAVA_OPTS so operator flags are applied (and win on conflict).
DEFAULT_EXTRA_JAVA_OPTS="-Xss4m -Dfile.encoding=UTF-8"
export EXTRA_JAVA_OPTS="${DEFAULT_EXTRA_JAVA_OPTS} ${EXTRA_JAVA_OPTS}"
# export KARAF_HOME # Karaf home folder
# export KARAF_DATA # Karaf data folder
# export KARAF_BASE # Karaf base folder
# export KARAF_ETC  # Karaf etc  folder
# export KARAF_LOG  # Karaf log  folder
# export KARAF_SYSTEM_OPTS # First citizen Karaf options
# export KARAF_OPTS # Additional available Karaf options
# export KARAF_DEBUG # Enable debug mode
# export KARAF_REDIRECT # Enable/set the std/err redirection when using bin/start
# export KARAF_NOROOT # Prevent execution as root if set to true

