#!/bin/bash # #https://wiki.debian.org/LSBInitScripts ### BEGIN INIT INFO # Provides: tomcat8 # Required-Start: $local_fs $remote_fs $network # Required-Stop: $local_fs $remote_fs $network # Should-Start: $named # Should-Stop: $named # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start Tomcat. # Description: Start the Tomcat servlet engine. ### END INIT INFO # Run Tomcat 8 as this user ID and group ID TOMCAT8_USER=tomcat8 TOMCAT8_GROUP=tomcat8 # this is a work-around until there is a suitable runtime replacement # for dpkg-architecture for arch:all packages # this function sets the variable JDK_DIRS find_jdks() { for java_version in 9 8 7 do for jvmdir in /usr/lib/jvm/java-${java_version}-openjdk-* \ /usr/lib/jvm/jdk-${java_version}-oracle-* \ /usr/lib/jvm/jre-${java_version}-oracle-* do if [ -d "${jvmdir}" ] then JDK_DIRS="${JDK_DIRS} ${jvmdir}" fi done done # Add older non multi arch installations JDK_DIRS="${JDK_DIRS} /usr/lib/jvm/java-7-oracle" } # The first existing directory is used for JAVA_HOME (if JAVA_HOME is not # defined in $DEFAULT) JDK_DIRS="/usr/lib/jvm/default-java" find_jdks # Look for the right JVM to use for jdir in $JDK_DIRS; do if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then JAVA_HOME="$jdir" fi done export JAVA_HOME export CATALINA_HOME=/opt/tomcat8 export PATH=$JAVA_HOME/bin:$PATH start() { echo "Starting Tomcat 8..." /bin/su -s /bin/bash $TOMCAT8_USER -c $CATALINA_HOME/bin/startup.sh } stop() { echo "Stopping Tomcat 8..." /bin/su -s /bin/bash $TOMCAT8_USER -c '$CATALINA_HOME/bin/shutdown.sh -force' } case $1 in start|stop) $1;; restart) stop; start;; *) echo "Usage : $0 <start|stop|restart>"; exit 1;; esac exit 0