Blog posts for November 2011

Windows Service for Jetty 7

How to install Jetty 7 as a Windows service

Earlier versions of Jetty came with a Windows Service wrapper but Jetty 7 does not.  To use Jetty in a production environment it is helpful to create a Windows service to run Jetty so that the service may run without manual intervention, like when the machine boots.  

One way to accomplish this task is to make use of the (Jakarta) Commons Daemon project.  In the example that follows I am using XWiki 3.2 that bundles Jetty 7.  XWiki 3.2 is unzipped to C:\apps\xwiki32 and Jetty 7 resides within at C:\apps\xwiki32\jetty.

Commons Daemon

First read about the commons daemon project at the following URL:

Download the native binaries for Windows from this URL:

The daemon project essentially provides two Executables for the Windows operating system:  prunmgr.exe and prunsrv.exe, collectively referred to as procrun.  In essence, procrun provides the capability to run arbitrary Java main methods as a Windows service.

Determine Java arguments when starting Jetty

In my case I wanted to run a web application called XWiki deployed to Jetty, and have Jetty run under the Windows SYSTEM account whenever the machine boots up.  I modified the start_xwiki.bat batch file to echo the Java command line before running java so I could capture all the arguments to Java.  You'll need these later when configuring procrun.

In my case, the Java command line XWiki 3.2 wanted to use when running Java was:

java -Xmx512m -XX:MaxPermSize=128m -Djetty.port=8080 -Djetty.home=jetty -DSTOP.KEY=xwiki -DSTOP.PORT=8079 -Dfile.encoding=UTF8 -Dorg.mortbay.jetty.Request.maxFormContentSize=1000000 -jar jetty/start.jar

Rename prunsrv.exe and prunmgr.exe to reflect your Jetty Service

Because Windows' Service manager (accessible from the Control Panel) identifies services by the executable filename used to start and stop the service, it is helpful to rename the two windows executables, prunsrv.exe and prunmgr.exe to reflect the fact this is a XWiki Jetty service.

cd \apps\xwiki32
copy prunsrv.exe XWikiJettyService.exe
copy prunmgr.exe XWikiJettyServiceManager.exe

Install Service

The following step configures procrun and installs the Windows Service.  The JVM arguments below correspond to the arguments we captured from the original Java command line invocation from start_xwiki.bat.

XWikiJettyService.exe  //IS//XWikiJettyServiceManager --DisplayName="XWiki Jetty Service" --Install=C:\apps\xwiki32\XWikiJettyService.exe --LogPath=C:\apps\xwiki32\jetty\logs --LogLevel=Debug --StdOutput=auto --StdError=auto --StartMode=Java --StopMode=Java --Jvm=auto --Startup=auto --JvmMx=512 --StartPath=C:\apps\xwiki32 ++JvmOptions=-XX:MaxPermSize=128m --Classpath=C:\apps\xwiki32\jetty\start.jar --StartClass=org.eclipse.jetty.start.Main --StopClass=org.eclipse.jetty.start.Main ++StopParams=--stop ++JvmOptions=-Djetty.home=C:\apps\xwiki32\jetty ++JvmOptions=-Djetty.port=8080 ++JvmOptions=-DSTOP.PORT=8079 ++JvmOptions=-DSTOP.KEY=xwiki ++JvmOptions=-Djetty.logs=C:\apps\xwiki32\jetty\logs ++JvmOptions=-Dfile.encoding=UTF8 ++JvmOptions=-Dorg.mortbay.jetty.Request.maxFormContentSize=1000000

Test procrun

The following will allow you to test your shiny new Windows Service by running it in the foreground so you can see any errors that may occur if the configuration isn't quite right.

XWikiJettyService.exe //TS/XWikiJettyServiceManager

Procrun logs, Stdout and Stderr logs for your service

These logs will be saved to the Jetty logs directory in the scenario described.  The location of the procrun daemon logs are specified by the
--LogPath=C:\apps\xwiki32\jetty\logs argument when you ran the XWikiJettyService.exe (prunsrv.exe) above.

The actual daemon stdout and stderr logs for Jetty are controlled by the -Djetty.logs=C:\apps\xwiki32\jetty\logs JVM argument.

Remove Service

cd \apps\xwiki32
XWikiJettyService.exe  //DS//XWikiJettyServiceManager

OpenWrt 10.03.1 dnsmasq.conf for gPXE

In the latest version of OpenWrt backfire version 10.03.1 the OpenWrt development team has added many new capabilities for configuring dnsmasq and the many options related to DHCP.

Dnsmasq in OpenWrt can be configured to support iSCSI and gPXE without resorting to creating a dnsmasq.conf file as I did in the 10.03 OpenWrt release.

The following link has the dnsmasq configuration syntax for the 10.03.1 release of OpenWrt.

This link has details on the dnsmasq daemon command line options.  It provides insight to use of the /etc/dnsmasq.conf file, if you choose to use it.

The syntax of /etc/dnsmasq.conf changed between 10.03 and 10.03.1 because dnsmasq changed versions from 2.52-2 to 2.55-6.

The 10.03 OpenWrt gPXE post can be referred to and the new dnsmasq.conf excerpt is below:

# required by old versions of gPXE (e.g. the one that comes with OracleVM)

# MAC-specific tags
dhcp-mac=set:ECS,00:14:aa:bb:cc:dd       # ECS mobo / Socket AM2 Athlon
dhcp-mac=set:SLI,00:11:bb:cc:dd:ee       # Asus A8N-SLI mobo forcedeth / Socket 939 Athlon X2

dhcp-match=set:OTHER,175            # tags the request with OTHER if the gPXE option was supplied in DHCP request

dhcp-option=175,8:1:1          # turn on the keep-san option to allow iSCSI-capable OS installation


## Last match wins!

#dhcp-boot=pxelinux.0                  # ONLY SET IF want gPXE to run script or chain-load pxelinux
dhcp-boot=tag:#OTHER,gpxe.0             # Here #OTHER means 'not OTHER': i.e. the tag is not set
#dhcp-boot=tag:ECS,sanboot-test.gpxe   # run gpxe script

Created by Administrator on 07/09/2013
This website content is not licensed to you. All rights reserved.
XWiki Enterprise 9.11.1 - Documentation