Jetty is a popular JSP/Servlet container from Mortbay
To install on Mandriva
- Install J2RE and J2SDK packages either from a commercial CD or build your own following the instructions on Jpackage.
- As root Create a user called Jetty
- Download a jetty extra install and extract to /home/jetty/jetty-VERSION
- Create a symlink to the version you just downloaded
ln -s /home/jetty/jetty-VERSION /home/jetty/jetty
- Create in /etc/profile.d a jetty.sh with the following contents
export JETTY_HOME=/home/jetty/jetty
export JETTY_LOG_DIR=/var/log/jetty
- Set permissions on this file
chmod a+x /etc/profile.d/jetty.sh
- Run it into our current shell (this is to avoid logging out and in to get the changes)
source /etc/profile.d/jetty.sh
- Make the log folder and set its owner
mkdir /var/log/jetty
chown jetty.jetty /var/log/jetty
- Copy a jetty.xml to /etc - you can write your own or use one of the samples. NOTE don't use one that listens on ports below 1000. To do this Jetty would need to run as root. If you want to achieve this you can use port fowarding to set port 80 to forward to 8080 or you can use Apache with an AJP13 listener.
cp /home/jetty/jetty/etc/jetty.xml /etc/jetty.xml
- Put the file below into /etc/init.d/jetty. This is derived from one in extra/unix/bin but with Mandrake specific stuff added and the ability to run as a user other than root.
#!/bin/sh#--------------------------------------------------------------
#
# Sample init.d stop/start script for jetty services on Linux.
#
#--------------------------------------------------------------
# chkconfig: 2345 20 80
# description: Runs Jetty HTTP Server
#
#JAVA_OPTS
#
#This variable can be used to pass args to the jvm
#
. /etc/rc.d/init.d/functions#
# The user name jetty should run under. THis should be able to write to the log dir
#
JETTY_USER=jetty
#
# DIRNAME, SCRIPTNAME
#
DIRNAME=`dirname $0`
SCRIPTNAME=`basename $0`#
# JAVA_HOME
#
if [ -z "$JAVA_HOME" ]; then
JAVA_HOME=/usr/lib/java
export JAVA_HOME
echo "JAVA_HOME not set, using default ${JAVA_HOME}"
fi
#
#JAVA_CMD
#
JAVA_CMD="${JAVA_HOME}/bin/java"
#
# JETTY_HOME
#
if [ -z "$JETTY_HOME" ]; then
JETTY_HOME=/usr/share/java/jetty
echo "JETTY_HOME not set, using default ${JETTY_HOME}"
fi
#
# JETTY_XML_FILE
#
if [ -z "$JETTY_XML_FILE" ]; then
JETTY_XML_FILE=/etc/jetty.xml
echo "JETTY_XML_FILE not set, using default xml config file: ${JETTY_XML_FILE}"
fi
#
# LOG_DIR
#
if [ -z "$JETTY_LOG_DIR" ]; then
JETTY_LOG_DIR=/var/log
echo "JETTY_LOG_DIR not set, using default ${JETTY_LOG_DIR}"
fitest -f "${JAVA_CMD}" || exit 0
test -d "${JETTY_HOME}" || exit 0rotate_logs()
{
if test -f ${JETTY_LOG_DIR}/jetty_bootstart_04
then
rm ${JETTY_LOG_DIR}/jetty_bootstart_04
fi
if test -f ${JETTY_LOG_DIR}/jetty_bootstart_03
then
mv ${JETTY_LOG_DIR}/jetty_bootstart_03 ${JETTY_LOG_DIR}/jetty_bootstart_04
fi
if test -f ${JETTY_LOG_DIR}/jetty_bootstart_02
then
mv ${JETTY_LOG_DIR}/jetty_bootstart_02 ${JETTY_LOG_DIR}/jetty_bootstart_03
fi
if test -f ${JETTY_LOG_DIR}/jetty_bootstart_01
then
mv ${JETTY_LOG_DIR}/jetty_bootstart_01 ${JETTY_LOG_DIR}/jetty_bootstart_02
fi
if test -f ${JETTY_LOG_DIR}/jetty_bootstart
then
mv ${JETTY_LOG_DIR}/jetty_bootstart ${JETTY_LOG_DIR}/jetty_bootstart_01
fi
}kill_jetty()
{
# Guarantee jetty exits
jetty_pid=""
for p in `ps -fC java | grep "$SCRIPTNAME" | tr -s " " | cut -f2 -d" "`
do
jetty_pid="$jetty_pid $p"
done if test -n "$jetty_pid"
then
# Grace
sleep 5
kill -4 $jetty_pid >/dev/null 2>&1
sleep 3
kill -9 $jetty_pid >/dev/null 2>&1
fi
}
startJetty()
{
gprintf "Starting Jetty Server: "
rotate_logs
sudo -u $JETTY_USER nohup $JAVA_CMD $JAVA_OPTS -Djetty.home=${JETTY_HOME} -jar ${JETTY_HOME}/start.jar ${JETTY_XML_FILE} > ${JETTY_LOG_DIR}/jetty_bootstart 2>&1 &
success
echo
}stopJetty()
{
gprintf "Stopping Jetty Server: "
sudo -u $JETTY_USER $JAVA_CMD $JAVA_OPTS -Djetty.home=${JETTY_HOME} -jar ${JETTY_HOME}/stop.jar ${JETTY_XML_FILE} > ${JETTY_LOG_DIR}/jetty_bootstop 2>&1
kill_jetty
success
echo
}
# Set umask for public read of created files
umask 0022# set the TZ for java logging
# some java/unix combos don't understand Daylight Savings Time
if test -z "${TZ}"
then
if test -f /etc/timezone
then
TZ="`cat /etc/timezone`"
export TZ
elif test -L /etc/localtime
then
# Symlink (RedHat style)
TZ="`ls -l /etc/localtime | sed -e 's%..*/usr/share/zoneinfo/%%g'`"
export TZ
elif test -f /etc/localtime
then
# Maybe it's a hardlink (SuSE Linux style)
tz_inode=`ls -i /etc/localtime | cut -f1 -d"/"`
TZ="`find /usr/share/zoneinfo -inum $tz_inode -print | sed -n 1p | sed -e 's%/usr/share/zoneinfo/%%g'`"
export TZ
fi
ficase "$1" in
start)
startJetty
;;
stop)
stopJetty
;;
restart|force-reload)
stopJetty
startJetty
;;
*) gprintf "Usage: /etc/init.d/${SCRIPTNAME} {start|stop|restart|force-reload}" >&2
exit 1
;;
esacexit 0
- Set permissions on the init script
chmod u+x /etc/init.d/jetty
- Now try starting Jetty for the first time
- If you used the sample configuration file point a web browser at localhost:8080 and you will get an error page telling what applications are installed on this jetty
|