summaryrefslogtreecommitdiff
path: root/www/jakarta-tomcat3/files/tomcatctl
blob: a28cac7623a2b4eeb2fb8f1ca128c37b497c61e8 (plain) (blame)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/bin/sh

# Set some variables
APP_HOME=%%APP_HOME%%
STDOUT_LOG=%%STDOUT_LOG%%
STDERR_LOG=%%STDERR_LOG%%
JAR_FILE=${APP_HOME}/lib/webserver.jar
MYSELF=`basename $0`

# Set the CLASSPATH
unset CLASSPATH
for i in ${APP_HOME}/lib/* ; do
	if [ "$CLASSPATH" != "" ]; then
		CLASSPATH=${CLASSPATH}:$i
	else
		CLASSPATH=$i
	fi
done
if [ -f ${JAVA_HOME}/lib/tools.jar ] ; then
	CLASSPATH=${CLASSPATH}:${JAVA_HOME}/lib/tools.jar
fi

# Check if the JAVA_HOME directory is defined, otherwise set it to the
# fallback default
if [ "${JAVA_HOME}a" = "a" ]; then
	JAVA_HOME=%%JAVA_HOME%%
fi
JAVA_CMD=${JAVA_HOME}/bin/java


##############################################################################
# Function that shows an error message
#
# This function is called by the 'checks' function
#
# Parameters:
#     1: The message to be displayed.

error() {
	echo -n "%%APP_SHORTNAME%%: ERROR: "
	echo $1
}


##############################################################################
# Function that performs all checks necessary for starting or stopping the
# application.
#
# This function is called by the 'start' and 'stop' functions
#
# This function expects no parameters

checks() {
	# Make sure the application directory does exist
	if [ ! -d ${APP_HOME} ]; then
		error "Unable to find %%APP_TITLE%% home directory at ${APP_HOME}."
		exit 2
	fi

	# Make sure the application JAR file exists
	if [ ! -r ${JAR_FILE} ]; then
		error "Unable to find %%APP_TITLE%% JAR file at ${JAR_FILE}."
		exit 3
	fi

	# Make sure the Java VM can be found
	if [ ! -x ${JAVA_CMD} ]; then
		error "Unable to find Java VM at ${JAVA_HOME}."
		exit 4
	fi
}


##############################################################################
# Functions that calls the application with the specified parameter
#
# Parameters:
#    1: The argument to pass to the application (optional)

app() {
	(cd ${APP_HOME} && ${JAVA_CMD} -cp ${CLASSPATH} -Dtomcat.home=${APP_HOME} org.apache.tomcat.startup.Tomcat $1 &) >> ${STDOUT_LOG} 2>> ${STDERR_LOG}
}


##############################################################################
# Function that starts the application
#
# This function is called from the main function
#
# This function expects no parameters

start() {
	# Perform the checks
	checks

	# Stop the application
	app
}


##############################################################################
# Function that stops the application
#
# This function is called from the main function
#
# This function expects no parameters

stop() {
	# Perform the checks
	checks

	# Stop the application
	app -stop
}


##############################################################################
# Main function. This function calls the 'start' and 'stop' functions.
#
# Parameters:
#    1: The argument to this shell script

main() {
	case "$1" in
		start)
			start
			;;
		stop)
			stop
			;;
		restart)
			stop
			start
			;;
		*)
			echo "Usage: ${MYSELF} { start | stop | restart }"
			exit 64
			;;
	esac
}


# Call the main function and exit
main $1
exit 0