This repository has been archived on 2022-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
appliances-old/guacamole/tomcat/tomcat.start

131 lines
3.2 KiB
Bash
Executable File

#!/bin/sh
# Author: Jens Koegler <j.koegler@web.de>
# based on the original init.d script
# set debugging on
# set -x
die() {
usage
exit 1
}
usage() {
cat <<EOL
Usage: ${BASH_SOURCE} [start|stop] <instance-name>
Usage: NAME=<instance> ${BASH_SOURCE} [start|stop]
Instance-name can be the environment variable NAME
EOL
}
if ([[ $# -gt 2 ]] || [[ $# -eq 0 ]]); then
die
fi
RUN=$1
TOMCAT=`basename ${BASH_SOURCE}`
if [ $# -eq 2 ]; then
printf -v INSTANCE "%s-%s" "$TOMCAT" "$2"
else
if [[ -z ${NAME} ]]; then
printf -v INSTANCE "%s" "$TOMCAT"
else
printf -v INSTANCE "%s-%s" "$TOMCAT" "$NAME"
fi
fi
if [[ -f /etc/conf.d/${INSTANCE} ]]; then
source /etc/conf.d/${INSTANCE}
else
echo "The configuration file /etc/conf.d/${INSTANCE} does not exist"
die
fi
: ${CATALINA_HOME:=/usr/share/${TOMCAT}}
: ${CATALINA_BASE:=/var/lib/${INSTANCE}}
: ${CATALINA_TMPDIR:=/var/tmp/${INSTANCE}}
: ${TOMCAT_START:=start}
: ${JPDA_TRANSPORT:="dt_socket"}
: ${JPDA_ADDRESS:="8000"}
: ${JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT},address=${JPDA_ADDRESS},server=y,suspend=n"}
if [ ! -e "${CATALINA_TMPDIR}" ]; then
mkdir -p "${CATALINA_TMPDIR}"
chown tomcat:tomcat "${CATALINA_TMPDIR}"
fi
export JAVA_HOME=`java-config ${TOMCAT_JVM:+--select-vm ${TOMCAT_JVM}} --jre-home`
export CLASSPATH="${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar"
start() {
if [ ! -e "${CATALINA_TMPDIR}" ]; then
mkdir -p "${CATALINA_TMPDIR}"
chown tomcat:tomcat "${CATALINA_TMPDIR}"
fi
local DEPEND=$(java-config --query DEPEND --package ${TOMCAT}):${TOMCAT_EXTRA_JARS}
DEPEND=${DEPEND%:}
local GCLASSPATH=$(java-config --with-dependencies --classpath "${DEPEND//:/,}"):${TOMCAT_EXTRA_CLASSPATH}
GCLASSPATH=${GCLASSPATH%:}
local cmd=java args=
if [ "${TOMCAT_START}" = "debug" ] || [ "${TOMCAT_START}" = "-security debug" ] ; then
cmd=jdb
args="${args} -sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share"
fi
if [ "${TOMCAT_START}" = "-security debug" ] || [ "${TOMCAT_START}" = "-security start" ]; then
args="${args} -Djava.security.manager"
args="${args} -Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy"
fi
if [ "${TOMCAT_START}" = "jpda start" ] ; then
args="${args} ${JPDA_OPTS}"
fi
if [ -r "${CATALINA_HOME}"/bin/tomcat-juli.jar ]; then
args="${args} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties"
fi
${JAVA_HOME}/bin/${cmd} \
${JAVA_OPTS} \
${args} \
'-XX:OnOutOfMemoryError=kill -9 %%p' \
-Dcatalina.base="${CATALINA_BASE}" \
-Dcatalina.home="${CATALINA_HOME}" \
-Djava.io.tmpdir="${CATALINA_TMPDIR}" \
-Dgentoo.classpath="${GCLASSPATH//:/,}" \
-classpath "${CLASSPATH}" \
org.apache.catalina.startup.Bootstrap \
${CATALINA_OPTS} \
${TOMCAT_START}
}
stop() {
${JAVA_HOME}/bin/java \
${JAVA_OPTS} \
${args} \
-Dcatalina.base="${CATALINA_BASE}" \
-Dcatalina.home="${CATALINA_HOME}" \
-Djava.io.tmpdir="${CATALINA_TMPDIR}" \
-Dgentoo.classpath="${GCLASSPATH//:/,}" \
-classpath "${CLASSPATH}" \
org.apache.catalina.startup.Bootstrap stop
}
case "${RUN}" in
start)
start
;;
stop)
stop
;;
*)
die
;;
esac