Created
July 11, 2012 10:33
-
-
Save oscarfonts/3089536 to your computer and use it in GitHub Desktop.
Manually installed tomcat init.d script for ubuntu-based systems
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Startup script for Jakarta Tomcat | |
# Script should work on Centos, Redhat and Fedora Linux. It depends on the file tomcatRunner. | |
# WARNING: The script does not allow to run Tomcat on privileged ports as non root user. | |
# For this use case try : http://tomcat.apache.org/tomcat-6.0-doc/setup.html and http://commons.apache.org/daemon/jsvc.html | |
# | |
# Should start normally after the databases and before http server | |
# chkconfig: 345 80 10 | |
# description: Jakarta Tomcat Java Servlet/JSP Container | |
# processname: geowebcache | |
# pidfile: /var/run/tomcat/geowebcache.pid | |
# source function library | |
#. /etc/rc.d/init.d/functions | |
##### In this area you can find settings which are likely to change frequently #### | |
JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.24 | |
JAVA="$JAVA_HOME/jre/bin/java" | |
# unprivileged user running Tomcat server | |
tomcatuser=geosolutions | |
# servicename used as pidfile and lockfile name, must correspond to 'processname:' at the top of this file | |
# If not linux will not detect the running service during runlevel switch and will not shut it down normally | |
servicename=stg_geoserver | |
# folder where Tomcat is installed | |
CATALINA_HOME=/var/tomcat/apache-tomcat-6.0.35 | |
# Options for the JVM | |
#JAVA_OPTS=-Xmx256m | |
#JAVA_OPTS=-Xmx512m -XX:MaxPermSize=128m | |
##### End of frequent settings area ##### | |
. /var/tomcat/stg_geoserver/bin/setenv.sh | |
#script used to startup tomcat | |
tomcatRunner=/etc/init.d/tomcatRunner | |
pidfile=/opt/processIds/$servicename | |
lockfile=/var/lock/subsys/$servicename | |
#runsecure=1 #starts tomcat with java security | |
runsecure=0 | |
# Optional additional libs you would like to add to the classpath (= JVM Option -classpath) | |
CLASSPATH="" | |
# Optional Java Security Socket extension | |
# CLASSPATH="$CLASSPATH":"$JSSE_HOME"/lib/jcert.jar:"$JSSE_HOME"/lib/jnet.jar:"$JSSE_HOME"/lib/jsse.jar | |
# path to Tomcat lib | |
CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar | |
# Directory holding configuration, defaults to CATALINA_HOME | |
# In a Tomcat cluster you might reuse the servicename to identify the base directory | |
#CATALINA_BASE="$CATALINA_HOME" | |
# server log during startup / shutdown | |
logfile=$CATALINA_BASE/logs/catalina.out | |
# endorsed allows to overwrite JVM libs -> JVM option -Djava.endorsed.dirs | |
#JAVA_ENDORSED_DIRS="$CATALINABASEDIR"/endorsed | |
# Define the java.io.tmpdir to use for Catalina | |
CATALINA_TMPDIR="$CATALINA_BASE"/temp | |
# Set juli LogManager if it is present | |
if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then | |
JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager" | |
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties" | |
fi | |
#### End of settings ##### | |
# build java command to start Tomcat | |
command="$JAVA $JAVA_OPTS $LOGGING_CONFIG $CATALINA_OPTS $LOGGING_CONFIG \ | |
-Djava.endorsed.dirs=$JAVA_ENDORSED_DIRS -classpath $CLASSPATH \ | |
-Dcatalina.base=$CATALINA_BASE \ | |
-Dcatalina.home=$CATALINA_HOME \ | |
-Djava.io.tmpdir=$CATALINA_TMPDIR" | |
if [ "$runsecure" = "1" ]; then | |
command="$command -Djava.security.manager -Djava.security.policy=$CATALINA_BASE/conf/catalina.policy" | |
fi | |
command="$pidfile $logfile $command org.apache.catalina.startup.Bootstrap" | |
start() | |
{ | |
echo -n $" Starting $servicename based at $CATALINA_BASE " | |
#daemon --user $tomcatuser --pidfile=$pidfile $command start | |
start-stop-daemon --start --user $tomcatuser --chuid $tomcatuser --pidfile $pidfile --name $servicename --exec $tomcatRunner -- $command start | |
RETVAL=$? | |
[ "$RETVAL" = 0 ] && touch $lockfile | |
echo | |
} | |
stop() | |
{ | |
echo -n $"Stopping $servicename: " | |
if [ ! -r $pidfile ]; then | |
echo "Pidfile $pidfile cannot be read" | |
RETVAL=1 | |
return | |
fi | |
# Sends TERM signal first and kills finally after 3 seconds | |
#killproc -p $pidfile -d 3 $servicename | |
#kill -INT `cat /var/run/tomcat/$servicename` | |
start-stop-daemon --stop --pidfile $pidfile | |
# Send TERM signal only, don't kill | |
# killproc -p $pidfile $servicename -15 | |
RETVAL=$? | |
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile} | |
echo | |
} | |
version() | |
{ | |
$JAVA -classpath $CATALINA_HOME/lib/catalina.jar org.apache.catalina.util.ServerInfo | |
RETVAL=$? | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
version) | |
version | |
;; | |
status) | |
status --system $pidfile $servicename | |
RETVAL=$? | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|restart|version|status}" | |
RETVAL=1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment