summaryrefslogtreecommitdiff
blob: 677bdbde0b948ccff68a4c2c9d749000f6095b94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/sbin/runscript
# Copyright 1999-2004 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/www-servers/tomcat/files/5.5.20/tomcat.init,v 1.4 2007/01/28 07:26:59 wltjr Exp $

init_env_vars() {
	# Set some sane defaults
	if [ -z "${CATALINA_TMPDIR}" ] ; then
		CATALINA_TMPDIR="${CATALINA_BASE}"/temp
	fi
	JPDA_TRANSPORT=${JPDA_TRANSPORT:="dt_socket"}
	JPDA_ADDRESS=${JPDA_ADDRESS:="8000"}
	JPDA_OPTS=${JPDA_OPTS="-Xdebug -Xrunjdwp:transport=${JPDA_TRANSPORT},address=${JPDA_ADDRESS},server=y,suspend=n"}

	# Activate Logging
	if [[ -r "${CATALINA_HOME}"/bin/tomcat-juli.jar ]]; then
		JAVA_OPTS="${JAVA_OPTS} -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager \
			-Djava.util.logging.config.file=${CATALINA_BASE}/conf/logging.properties"
	fi

	# Populate the classpath
	CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/server/lib:${JAVA_HOME}/lib/tools.jar"
	if [[ -n "${JSSE_HOME}" ]]; then
		CLASSPATH="${CLASSPATH}:${JSSE_HOME}/lib/jcert.jar:${JSSE_HOME}/lib/jnet.jar:${JSSE_HOME}/lib/jsse.jar"
	fi
	CLASSPATH="${CLASSPATH}:${CATALINA_HOME}/bin/bootstrap.jar:${CATALINA_HOME}/bin/commons-logging-api.jar"

	OPTS_CP="${JAVA_OPTS} ${CATALINA_OPTS} \
			 -Djava.endorsed.dirs=${CATALINA_HOME}/common/endorsed \
			 -classpath ${CLASSPATH}"

	CATALINA_ARGS="-Dcatalina.base=${CATALINA_BASE} \
				   -Dcatalina.home=${CATALINA_HOME} \
				   -Djava.io.tmpdir=${CATALINA_TMPDIR} \
				   org.apache.catalina.startup.Bootstrap "

	if [ ! -f "${CATALINA_BASE}logs/catalina.out" ]; then
		touch "${CATALINA_BASE}logs/catalina.out"
		chown tomcat:tomcat "${CATALINA_BASE}logs/catalina.out"
	fi
}

start-helper() {
	local executor=${1}
	shift
	local arguments="--start --quiet --background --chuid ${CATALINA_USER}:${CATALINA_GROUP} \
		--make-pidfile --pidfile /var/run/tomcat.pid"
	start-stop-daemon ${arguments} --exec ${executor} -- ${OPTS_CP} "$@" ${CATALINA_ARGS} ${TOMCAT_START} >> "$CATALINA_BASE"/logs/catalina.out 2>&1
	return $?
}

depend() {
	use dns logger net
}

start()	{
	ebegin "Starting Tomcat"
	init_env_vars
	# Figure out what arguments to pass start-helper based on TOMCAT_START
	if [[ "${TOMCAT_START}" == "debug" ]] ; then
		start-helper ${JAVA_HOME}/bin/jdb \
			-sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share
	elif [[ "${TOMCAT_START}" == "debug -security" ]] ; then
		start-helper ${JAVA_HOME}/bin/jdb \
			-sourcepath ${CATALINA_HOME}/../../jakarta-tomcat-catalina/catalina/src/share \
			-Djava.security.manager \
			-Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy
	elif [[ "${TOMCAT_START}" == "jpda start" ]] ; then
		start-helper ${JAVA_HOME}/bin/java ${JPDA_OPTS}
	elif [[ "${TOMCAT_START}" == "start" ]] ; then
		start-helper ${JAVA_HOME}/bin/java
	elif [[ "${TOMCAT_START}" == "start -security" ]] ; then
		start-helper ${JAVA_HOME}/bin/java \
			-Djava.security.manager \
			-Djava.security.policy=${CATALINA_BASE}/conf/catalina.policy
	else
		eerror "Invalid TOMCAT_START variable value, or one is not set"
		eerror "Please see /etc/conf.d/tomcat-5.5 for more information"
		eend 1
	fi
	eend $?
}

stop()	{
	ebegin "Stopping Tomcat"
	init_env_vars
	start-stop-daemon --stop --quiet \
	       	--make-pidfile --pidfile /var/run/tomcat.pid \
			--exec ${JAVA_HOME}/bin/java -- ${OPTS_CP} ${CATALINA_ARGS} ${STD_OUT} stop
	eend $?
}