3
# /etc/init.d/tomcat7 -- startup script for the Tomcat 6 servlet engine
5
# Written by Miquel van Smoorenburg <miquels@cistron.nl>.
6
# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
7
# Modified for Tomcat by Stefan Gybas <sgybas@debian.org>.
8
# Modified for Tomcat6 by Thierry Carrez <thierry.carrez@ubuntu.com>.
9
# Modified for Tomcat7 by Ernesto Hernandez-Novich <emhn@itverx.com.ve>.
10
# Additional improvements by Jason Brittain <jason.brittain@mulesoft.com>.
14
# Required-Start: $local_fs $remote_fs $network
15
# Required-Stop: $local_fs $remote_fs $network
16
# Should-Start: $named
18
# Default-Start: 2 3 4 5
20
# Short-Description: Start Tomcat.
21
# Description: Start the Tomcat servlet engine.
26
PATH=/bin:/usr/bin:/sbin:/usr/sbin
28
DESC="Tomcat servlet engine"
29
DEFAULT=/etc/default/$NAME
30
JVM_TMP=/tmp/tomcat7-$NAME-tmp
32
if [ `id -u` -ne 0 ]; then
33
echo "You need root privileges to run this script"
37
# Make sure tomcat is started with system locale
38
if [ -r /etc/default/locale ]; then
43
. /lib/lsb/init-functions
45
if [ -r /etc/default/rcS ]; then
50
# The following variables can be overwritten in $DEFAULT
52
# Run Tomcat 7 as this user ID and group ID
56
# this is a work-around until there is a suitable runtime replacement
57
# for dpkg-architecture for arch:all packages
58
# this function sets the variable OPENJDKS
61
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
63
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
68
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
70
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
72
OPENJDKS="${OPENJDKS} ${jvmdir}"
79
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
80
# defined in $DEFAULT)
81
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle"
83
# Look for the right JVM to use
84
for jdir in $JDK_DIRS; do
85
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
91
# Directory where the Tomcat 6 binary distribution resides
92
CATALINA_HOME=/usr/share/$NAME
94
# Directory for per-instance configuration files and webapps
95
CATALINA_BASE=/var/lib/$NAME
97
# Use the Java security manager? (yes/no)
100
# Default Java options
101
# Set java.awt.headless=true if JAVA_OPTS is not set so the
102
# Xalan XSL transformer can work without X11 display on JDK 1.4+
103
# It also looks like the default heap size of 64M is not enough for most cases
104
# so the maximum heap size is set to 128M
105
if [ -z "$JAVA_OPTS" ]; then
106
JAVA_OPTS="-Djava.awt.headless=true -Xmx128M"
109
# End of variables that can be overwritten in $DEFAULT
111
# overwrite settings from default file
112
if [ -f "$DEFAULT" ]; then
116
if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
117
log_failure_msg "$NAME is not installed"
121
POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"
123
if [ -z "$CATALINA_TMPDIR" ]; then
124
CATALINA_TMPDIR="$JVM_TMP"
127
# Set the JSP compiler if set in the tomcat7.default file
128
if [ -n "$JSP_COMPILER" ]; then
129
JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
133
if [ "$TOMCAT7_SECURITY" = "yes" ]; then
137
# Define other required variables
138
CATALINA_PID="/var/run/$NAME.pid"
139
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"
141
# Look for Java Secure Sockets Extension (JSSE) JARs
142
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
143
JSSE_HOME="${JAVA_HOME}/jre/"
147
# Escape any double quotes in the value of JAVA_OPTS
148
JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"
151
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
152
AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
155
# Define the command to run Tomcat's catalina.sh as a daemon
156
# set -a tells sh to export assigned variables to spawned shells.
157
TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
158
CATALINA_HOME=\"$CATALINA_HOME\"; \
159
CATALINA_BASE=\"$CATALINA_BASE\"; \
160
JAVA_OPTS=\"$JAVA_OPTS\"; \
161
CATALINA_PID=\"$CATALINA_PID\"; \
162
CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
163
LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
164
cd \"$CATALINA_BASE\"; \
167
if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
168
TOMCAT_SH="'$TOMCAT_SH'"
171
# Run the catalina.sh script as a daemon
173
touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
174
chown $TOMCAT7_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
175
start-stop-daemon --start -b -u "$TOMCAT7_USER" -g "$TOMCAT7_GROUP" \
176
-c "$TOMCAT7_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
177
-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
185
if [ -z "$JAVA_HOME" ]; then
186
log_failure_msg "no JDK or JRE found - please set JAVA_HOME"
190
if [ ! -d "$CATALINA_BASE/conf" ]; then
191
log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
195
log_daemon_msg "Starting $DESC" "$NAME"
196
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
197
--user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \
200
# Regenerate POLICY_CACHE file
202
echo "// AUTO-GENERATED FILE from /etc/tomcat7/policy.d/" \
204
echo "" >> "$POLICY_CACHE"
205
cat $CATALINA_BASE/conf/policy.d/*.policy \
208
# Remove / recreate JVM_TMP directory
210
mkdir -p "$JVM_TMP" || {
211
log_failure_msg "could not create JVM temporary directory"
214
chown $TOMCAT7_USER "$JVM_TMP"
216
catalina_sh start $SECURITY
218
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
219
--user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \
221
if [ -f "$CATALINA_PID" ]; then
222
rm -f "$CATALINA_PID"
229
log_progress_msg "(already running)"
234
log_daemon_msg "Stopping $DESC" "$NAME"
237
if [ -f "$CATALINA_PID" ]; then
238
start-stop-daemon --stop --pidfile "$CATALINA_PID" \
239
--user "$TOMCAT7_USER" \
240
--retry=TERM/20/KILL/5 >/dev/null
241
if [ $? -eq 1 ]; then
242
log_progress_msg "$DESC is not running but pid file exists, cleaning up"
243
elif [ $? -eq 3 ]; then
244
PID="`cat $CATALINA_PID`"
245
log_failure_msg "Failed to stop $NAME (pid $PID)"
248
rm -f "$CATALINA_PID"
251
log_progress_msg "(not running)"
258
start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
259
--user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \
261
if [ "$?" = "0" ]; then
263
if [ -f "$CATALINA_PID" ]; then
264
log_success_msg "$DESC is not running, but pid file exists."
267
log_success_msg "$DESC is not running."
271
log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
275
restart|force-reload)
276
if [ -f "$CATALINA_PID" ]; then
283
if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
284
--user $TOMCAT7_USER --exec "$JAVA_HOME/bin/java" \
290
log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"