PageRenderTime 52ms CodeModel.GetById 30ms app.highlight 2ms RepoModel.GetById 18ms app.codeStats 1ms

/www-servers/tomcat/files/6/tomcat.init.3

http://github.com/funtoo/portage
Unknown | 123 lines | 108 code | 15 blank | 0 comment | 0 complexity | 644db62d022588117a2fb6163f0d0ffb MD5 | raw file
  1#!/sbin/runscript
  2# Copyright 1999-2011 Gentoo Foundation
  3# Distributed under the terms of the GNU General Public License v2
  4# $Header: /var/cvsroot/gentoo-x86/www-servers/tomcat/files/6/tomcat.init.3,v 1.3 2011/04/08 11:25:06 elvanor Exp $
  5
  6opts="${opts} forcestop"
  7
  8init_env_vars() {
  9	# Populate JAVA_HOME
 10	JAVA_HOME=`java-config --jre-home`
 11
 12	# Set some sane defaults
 13	if [ -z "${CATALINA_TMPDIR}" ] ; then
 14		CATALINA_TMPDIR="${CATALINA_BASE}"/temp
 15	fi
 16	JPDA_TRANSPORT=${JPDA_TRANSPORT:="dt_socket"}
 17	JPDA_ADDRESS=${JPDA_ADDRESS:="8000"}
 18	JPDA_OPTS=${JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT},address=${JPDA_ADDRESS},server=y,suspend=n"}
 19
 20	# Activate Logging
 21	if [ -r "${CATALINA_HOME}"/bin/tomcat-juli.jar ]; then
 22		JAVA_OPTS="${JAVA_OPTS} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
 23			-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties"
 24	fi
 25
 26	# Populate the classpath
 27	unset CLASSPATH
 28	CLASSPATH="${CATALINA_HOME}/lib:${JAVA_HOME}/lib/tools.jar"
 29	if [ -n "${JSSE_HOME}" ]; then
 30		CLASSPATH="${CLASSPATH}:${JSSE_HOME}/lib/jcert.jar:${JSSE_HOME}/lib/jnet.jar:${JSSE_HOME}/lib/jsse.jar"
 31	fi
 32	CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/tomcat-juli.jar"
 33
 34	OPTS_CP="${JAVA_OPTS} ${CATALINA_OPTS} -classpath ${CLASSPATH}"
 35
 36	CATALINA_ARGS="-Dcatalina.base=${CATALINA_BASE} \
 37			-Dcatalina.home=${CATALINA_HOME} \
 38			-Djava.io.tmpdir=${CATALINA_TMPDIR} \
 39			org.apache.catalina.startup.Bootstrap "
 40
 41	if [ ! -f "${CATALINA_BASE}logs/catalina.out" ]; then
 42		touch "${CATALINA_BASE}logs/catalina.out"
 43		chown "${CATALINA_USER}:${CATALINA_GROUP}" "${CATALINA_BASE}logs/catalina.out"
 44	fi
 45}
 46
 47ssd() {
 48	local exec=${1}
 49	shift
 50	local args="--start --quiet \
 51		--chdir "${CATALINA_TMPDIR}" \
 52		--chuid ${CATALINA_USER}:${CATALINA_GROUP} \
 53		--make-pidfile --pidfile /var/run/tomcat-6.pid"
 54
 55	# bug #243348
 56	if [ -e /etc/init.d/sysfs ] ; then
 57		args="${args} --background \
 58			 --stdout ${CATALINA_BASE}/logs/catalina.out \
 59			 --stderr ${CATALINA_BASE}/logs/catalina.out"
 60		start-stop-daemon ${args} --exec ${exec} -- ${OPTS_CP} "$@" ${CATALINA_ARGS} ${TOMCAT_START}
 61	else
 62		start-stop-daemon ${args} --name ${exec} --exec ${exec} -- ${OPTS_CP} "$@" ${CATALINA_ARGS} ${TOMCAT_START} >> \
 63			"${CATALINA_BASE}/logs/catalina.out" 2>&1 &
 64	fi
 65	return $?
 66}
 67
 68depend() {
 69	use dns logger net
 70}
 71
 72start()	{
 73	ebegin "Starting Tomcat"
 74	init_env_vars
 75
 76	if [ ! -e "${CATALINA_TMPDIR}" ]; then
 77		eerror "CATALINA_TMPDIR does not exist. Unable to start tomcat."
 78		eerror "Please see /etc/conf.d/tomcat-6 for more information."
 79		eend 1
 80	fi
 81
 82	# Figure out what args to pass start_helper based on TOMCAT_START
 83	if [ "${TOMCAT_START}" = "debug" ] ; then
 84		ssd ${JAVA_HOME}/bin/jdb \
 85			-sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share
 86	elif [ "${TOMCAT_START}" = "-security debug" ] ; then
 87		ssd ${JAVA_HOME}/bin/jdb \
 88			-sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share \
 89			-Djava.security.manager \
 90			-Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy
 91	elif [ "${TOMCAT_START}" = "jpda start" ] ; then
 92		ssd ${JAVA_HOME}/bin/java ${JPDA_OPTS}
 93	elif [ "${TOMCAT_START}" = "start" ] ; then
 94		ssd ${JAVA_HOME}/bin/java
 95	elif [ "${TOMCAT_START}" = "-security start" ] ; then
 96		ssd ${JAVA_HOME}/bin/java \
 97			-Djava.security.manager \
 98			-Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy
 99	else
100		eerror "Invalid TOMCAT_START variable value, or one is not set"
101		eerror "Please see /etc/conf.d/tomcat-6 for more information"
102		eend 1
103	fi
104	eend $?
105}
106
107stop()	{
108	ebegin "Stopping Tomcat"
109	init_env_vars
110	start-stop-daemon --stop --quiet --retry=60 \
111	       	--pidfile /var/run/tomcat-6.pid \
112		--exec ${JAVA_HOME}/bin/java -- ${OPTS_CP} ${CATALINA_args} stop ${STD_OUT}
113	eend $?
114}
115forcestop()	{
116	ebegin "Forcing Tomcat to Stop"
117	start-stop-daemon --stop --quiet --retry=60 \
118		--pidfile /var/run/tomcat-6.pid --signal=9
119	if service_started "${SVCNAME}"; then
120		mark_service_stopped "${SVCNAME}"
121	fi
122	eend $?
123}