Tutorial: jetty

I really like Ruby but sometimes you need/want to run some Java apps on your vps. This is quite easy because you can strip down the Java VM to use quite a small amount of RAM.

But if you need to support servlets, websockets, JMX or JNDI lookups you need a container, or at least a servlet container.

You should not try to run the big application servers on a small vps - just by looking to the footprint of Jboss, Glassfish or Websphere.

But you can easily run Jetty on a small vps.

So let's install Jetty:

  • Install Java

    apt-get install openjdk-7-jdk (wopping 363MB)
    
    mkdir /usr/java
    
    For 64bit:
    ln -s /usr/lib/jvm/java-7-openjdk-amd64 /usr/java/default
    
    For 32bit
    ln -s /usr/lib/jvm/java-7-openjdk-i386/ /usr/java/default
    
  • Download Jetty
    http://download.ecli.../stable-9/dist/

    wget http://eclipse.org/downloads/download.php?file=/jetty/stable-9/dist/jetty-distribution-9.0.5.v20130815.tar.gz&r=1
    tar -xzf *.tar.gz
    
  • Prepare directories and users

    mkdir /opt
    mv jetty-distribution-9.0.5.v20130815 /opt/jetty
    
    useradd jetty -U -s /bin/false
    chown -R jetty:jetty /opt/jetty
    
  • Configure Jetty defaults

    nano /etc/default/jetty
    

    Contents:

    JAVA=/usr/bin/java # Path to Java
    NO_START=0 # Start on boot
    JETTY_HOST=127.0.0.1 # Listen to following ip
    JETTY_ARGS=jetty.port=8085 # Web port of jetty
    JETTY_USER=jetty # User to run under
    
  • Configure Jetty as a service

    cp /opt/jetty/bin/jetty.sh /etc/init.d/jetty
    chmod +x /etc/init.d/jetty
    
    update-rc.d jetty defaults
    
    service jetty restart
    
  • Remove demo apps (because they are not secure)

    cd /opt/jetty/webapps
    rm -rf test.d/ test.war test.xml async-rest.war
    rm -rf /opt/jetty/webapps.demo
    

If you look to the footprint of Jetty:

  PID User     Command                         Swap      USS      PSS      RSS
 7358 jetty    /usr/bin/java -Djetty.state    37456    40388    40492    41464

no one can say that Jetty is bloated.

Maybe enough to bring back some Java to your vps.

PS: One Jetty based project: Bombermine.

Configuration of Jetty

All config files are located in "/opt/jetty/etc"

/opt/jetty/etc# ls
README.spnego          jetty-deploy.xml    jetty-jmx.xml           jetty-proxy.xml       jetty-spdy.xml     jetty.conf        spnego.conf
jdbcRealm.properties   jetty-http.xml      jetty-logging.xml       jetty-requestlog.xml  jetty-ssl.xml      jetty.xml         spnego.properties
jetty-annotations.xml  jetty-https.xml     jetty-lowresources.xml  jetty-rewrite.xml     jetty-started.xml  keystore          test-realm.xml
jetty-debug.xml        jetty-ipaccess.xml  jetty-monitor.xml       jetty-setuid.xml      jetty-stats.xml    krb5.ini          webdefault.xml
jetty-demo.xml         jetty-jaas.xml      jetty-plus.xml          jetty-spdy-proxy.xml  jetty-xinetd.xml   realm.properties
  • jetty-http.xml
    Host and port of the http port
  • jetty-https.xml
    Port and certs for SSL
  • jetty.xml
    All major settings like:

    • Thread pool
        
          
          
          
          false
        
    
    • HTTP protocol
        
          https
          
          32768
          8192
          8192
          true
          false
          512
    
          
          
            
          
        
    

Best place to set the virtual hosts: Within the war file:


  /ibadmin
  /ibadmin.war

  
    
      test.wlanboy.com
      @ConnectorName
      localhost
      127.0.0.1