source: trunk/dports/java/tomcat5/files/tomcatctl @ 72252

Last change on this file since 72252 was 30857, checked in by jberry@…, 12 years ago

Update tomcat5 --> 5.5.25. Should resolve #13112.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.1 KB
Line 
1#!/bin/sh
2#
3#       tomcatctl
4#
5#       Tomcat control script to control tomcat running under jsvc.
6#
7#       USAGE: tomcatctl [--jdpa] start|stop|restart|status|info
8#
9
10# To be customized by installer...
11PREFIX=
12TOMCAT_USER=
13
14WC=wc
15JSVC="$PREFIX/bin/jsvc"
16#JSVC_ENV=
17#JSVC_DEBUG="-debug -verbose"
18
19
20# Calculate CATALINA_HOME based on our location
21if [ -z "$CATALINA_HOME" ]; then
22    # Handle symlinks
23    PRG="$0"   
24    while [ -L "$PRG" ]; do
25        ls=`ls -ld "$PRG"`
26        link=`expr "$ls" : '.*-> \(.*\)$'`
27        if expr "$link" : '/.*' > /dev/null; then
28            PRG="$link"
29        else
30            PRG="`dirname $PRG`/$link"
31        fi
32    done
33   
34    pushd "`dirname \"$PRG\"`/.." > /dev/null
35    CATALINA_HOME="`pwd -P`"
36    popd > /dev/null
37fi
38
39# Source the setenv.sh file to allow user to configure environment
40# including JAVA_HOME
41if [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
42    . "$CATALINA_HOME/bin/setenv.sh"
43fi
44
45# Source the setclasspath.sh file to allow setup of the CLASSPATH variable
46BASEDIR="$CATALINA_HOME"
47. "$CATALINA_HOME/bin/setclasspath.sh"
48
49# Set variable default values
50[ -z "$CATALINA_BASE" ]         && CATALINA_BASE="${CATALINA_HOME}"
51[ -z "$CATALINA_TMPDIR" ]       && CATALINA_TMPDIR="${CATALINA_BASE}/temp"
52
53[ -z "$TOMCAT_PIDNAME" ]        && TOMCAT_PIDNAME="tomcat5.pid"
54[ -z "$TOMCAT_PIDFILE" ]        && TOMCAT_PIDFILE="${CATALINA_BASE}/logs/${TOMCAT_PIDNAME}"
55[ -z "$TOMCAT_USER" ]           && TOMCAT_USER=tomcat
56
57[ -z "$JAVA_ENDORSED_DIRS" ]    && JAVA_ENDORSED_DIRS=${CATALINA_BASE}/common/endorsed
58
59[ -z "$JPDA_TRANSPORT" ]        && JPDA_TRANSPORT=dt_socket
60[ -z "$JPDA_ADDRESS" ]          && JPDA_ADDRESS=8000
61
62CLASSPATH="$CLASSPATH":"$CATALINA_HOME"/bin/bootstrap.jar:"$CATALINA_HOME"/bin/commons-logging-api.jar
63
64if [ -r "${CATALINA_HOME}/bin/tomcat-juli.jar" ]; then
65  JAVA_OPTS="$JAVA_OPTS -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
66fi
67
68usage()
69{
70    cat <<EOT
71USAGE: `basename $0` [--jpda] start|stop|restart|status|info
72EOT
73}
74
75
76check()
77{
78    PID=
79    RUNNING=
80    STATUS=
81   
82    if [ -f "$TOMCAT_PIDFILE" ]; then
83        PID=`cat $TOMCAT_PIDFILE`
84        if [ -n "$PID" -a `ps $PID | $WC -l` -gt 1 ]; then
85            STATUS="running (pid $PID)"
86            RUNNING=$PID
87        else
88            STATUS="not running (stale pid $PID?)"
89            RUNNING=
90        fi
91    else
92        STATUS="not running"
93        RUNNING=
94    fi
95}
96
97
98start()
99{
100        # Run conf_setup.sh to check and repair the conf directory
101        if [ -x "$CATALINA_HOME/bin/conf_setup.sh" ]; then
102                CATALINA_BASE="$CATALINA_BASE" "$CATALINA_HOME/bin/conf_setup.sh"
103        fi
104
105    printf "Starting Tomcat..."
106    check
107   
108    if [ -n "$RUNNING" ]; then
109        printf "already $STATUS\n"
110    else
111        # Remove any existing pid file
112        rm -f "$TOMCAT_PIDFILE"
113       
114        # Start Tomcat using jsvc
115        $JSVC_ENV $JSVC $JSVC_DEBUG $JAVA_OPTS $JPDA_OPTS \
116            -home "$JAVA_HOME" \
117            -user "$TOMCAT_USER" \
118            -classpath "${CLASSPATH}" \
119            -pidfile "$TOMCAT_PIDFILE" \
120            -outfile "$CATALINA_BASE/logs/catalina.out" \
121            -errfile "$CATALINA_BASE/logs/catalina.err" \
122            -Dcatalina.home="$CATALINA_HOME" \
123            -Dcatalina.base="$CATALINA_BASE" \
124            -Djava.io.tmpdir="$CATALINA_TMPDIR" \
125            -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" \
126            org.apache.catalina.startup.Bootstrap "$@" start
127           
128        # Wait for it to really start
129        for ((CNT=0; CNT < 15; ++CNT)); do
130            [ -f "$TOMCAT_PIDFILE" ] && break
131            printf "."
132            sleep 1
133        done
134       
135        # Let 'em know what happened
136        check
137        if [ -n "$RUNNING" ]; then
138            printf " started. (pid $PID)\n"
139        else
140            printf " giving up.\n"
141        fi
142    fi
143}
144
145
146stop()
147{
148    printf "Stopping Tomcat..."
149    check
150   
151    if [ -z "$RUNNING" ]; then
152        printf "already $STATUS\n"
153    else
154        printf "(pid $PID)"
155       
156        # Stop Tomcat
157        kill $PID
158       
159        # Wait for it to really stop
160        for ((CNT=0; CNT < 15; ++CNT)); do
161            [ -f "$TOMCAT_PIDFILE" ] || break
162            printf "."
163            sleep 1
164        done
165       
166        # Let 'em know what happened
167        check
168        if [ -z "$RUNNING" ]; then
169            printf " stopped.\n"
170        else
171            printf " giving up.\n"
172        fi
173    fi
174}
175
176
177# Ensure at least one parameter
178if [ $# -lt 1 ]; then
179   usage
180   exit 1
181fi
182
183# Parameter Handling
184while [ $# -gt 0 ]; do
185        case "$1" in
186        --jpda)
187                [ -z "$JPDA_OPTS" ] && JPDA_OPTS="-Xdebug -Xrunjdwp:transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=n"
188                ;;
189               
190        start)
191                start
192                ;;
193               
194        stop)
195                stop
196                ;;
197               
198        restart)
199                stop
200                start
201                ;;
202               
203        status)
204                check
205                printf "Tomcat is $STATUS\n"
206                ;;
207               
208        info)
209                check
210                cat <<EOT
211       
212Tomcat is $STATUS
213
214CATALINA_HOME       $CATALINA_HOME
215CATALINA_BASE       $CATALINA_BASE
216CATALINA_TMPDIR     $CATALINA_TMPDIR
217JAVA_HOME           $JAVA_HOME
218CLASSPATH           $CLASSPATH
219TOMCAT_PIDFILE      $TOMCAT_PIDFILE
220JAVA_OPTS           $JAVA_OPTS
221JPDA_OPTS           $JPDA_OPTS
222EOT
223                ;;
224               
225        *)
226                printf "$0: unrecognized option '$1'\n"
227                usage
228                exit 1
229                ;;
230        esac
231       
232        shift
233done
234
235
Note: See TracBrowser for help on using the repository browser.