Space Menu Home Downloads Goodies Newbie Area Documentation Knowledge Base E-Training Forum Blogs RPM Farm Linux Events
HistoryHistory |


Jetty

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
adduser 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#--------------------------------------------------------------
  1. Sample init.d stop/start script for jetty services on Linux.
  2. chkconfig: 2345 20 80
  3. description: Runs Jetty HTTP Servernull
      1. null
      2. variable can be used to pass args to the jvmnull
    null

  • /etc/rc.d/init.d/functions
    1. The user name jetty should run under. THis should be able to write to the log dir
    2. DIRNAME, SCRIPTNAME
    null
      1. null
      2. null
        1. null
        2. null
        3. null
        4. null
        5. null
          1. null
          2. null
            1. null
            2. null
            3. $0`nullnull
            nullnull
          nullnullnullnullnull
        nullnull
    • nullSCRIPTNAME=`basename $0`
      1. JAVA_HOME
      null
    • null
    • null
      1. null
      2. class="java-keyword">if [ -z "$JAVA_HOME" ]; thennull
    • null
    • null
    • null JAVA_HOME=/usr/lib/java export JAVA_HOME echo "JAVA_HOME not set, using default ${JAVA_HOME}" fi null
      1. null
        1. null
        2. null
        3. null
        4. null
        5. null
        6. null
        7. null
        8. null
          1. null
          2. class="java-quote">"${JAVA_HOME}/bin/java"null
          nullnullnullnullnullnullnullnull
        null
    • null
      1. JETTY_HOME
      null
    • null
    • null
      1. null
      2. class="java-keyword">if [ -z "$JETTY_HOME" ]; thennull
    • null
    • null
    • null JETTY_HOME=/usr/share/java/jetty echo "JETTY_HOME not set, using default ${JETTY_HOME}" fi
      1. JETTY_XML_FILE
      null
    • null
    • null
      1. null
      2. class="java-keyword">if [ -z "$JETTY_XML_FILE" ]; thennull
    • null
    • null
    • null JETTY_XML_FILE=/etc/jetty.xml echo "JETTY_XML_FILE not set, using default xml config file: ${JETTY_XML_FILE}" fi
      1. LOG_DIR
      null
    • null
    • null
      1. null
      2. class="java-keyword">if [ -z "$JETTY_LOG_DIR" ]; thennull
    • null
    • null
    • null JETTY_LOG_DIR=/var/log echo "JETTY_LOG_DIR not set, using default ${JETTY_LOG_DIR}" fi

      test -f "${JAVA_CMD}" || exit 0 test -d "${JETTY_HOME}" || exit 0

      rotate_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() {

      1. 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

      1. 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 }

      1. Set umask for public read of created files
      umask 0022
      1. set the TZ for java logging
      2. 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
      1. Symlink (RedHat style)
      TZ="`ls -l /etc/localtime | sed -e 's%..*/usr/share/zoneinfo/%%g'`" export TZ elif test -f /etc/localtime then
      1. 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 fi

      case "$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 ;; esac

      exit 0

  • 
              
  • Set permissions on the init script
chmod u+x /etc/init.d/jetty
  • Now try starting Jetty for the first time
/etc/init.d/jetty start
  • 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

RSS
KB.JavaDevelopment > Jetty (en)
Creator: bgidley  Date: 2005/06/20 10:44
Last Author: kilikopela  Date: 2006/01/28 22:14
Copyright (c) 2006 Mandriva