Below is some information about how to configure ServiceMix to be used as a windows (NT) service.
This capability is provided by the very useful Java Wrapper Service
The license of the Java Service Wrapper changed with version 3.3.0 to dual GPLv2 and commercial licensing. Make sure to download
an older version < 3.3.0 to have the old licensing
OR
switch to Apache Commons Daemon. Have a look at this website .
It should be noted that this is just one way to configure ServiceMix for this capability, but it should be the least intrusive.
First, download the Java Wrapper Service binary.
Next, extract the following files:
File |
into Directory |
---|---|
wrapper.exe |
base ServiceMix directory |
wrapper.jar |
ServiceMix lib directory |
wrapper.dll |
ServiceMix lib directory |
Now, create a wrapper.conf file in the conf directory. A sample version is provided below. This file may need to be modified to suit your specific needs.
#******************************************************************** # ServiceMix Wrapper Properties # #******************************************************************** # Java Application wrapper.java.command=c:/jdk1.5.0_10/bin/java # Java Main class. This class must implement the WrapperListener interface # or guarantee that the WrapperManager class is initialized. Helper # classes are provided to do this for you. See the Integration section # of the documentation for details. wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp wrapper.app.parameter.1=org.codehaus.classworlds.Launcher # Java Classpath (include wrapper.jar) Add class path elements as # needed starting from 1 wrapper.java.classpath.1=lib/wrappertest.jar wrapper.java.classpath.2=lib/wrapper.jar wrapper.java.classpath.3=lib/classworlds-1.0.1.jar wrapper.java.classpath.4=conf wrapper.java.classpath.5=. # Java Library Path (location of Wrapper.DLL or libwrapper.so) wrapper.java.library.path.1=lib # Java Additional Parameters #wrapper.java.additional.1= wrapper.java.additional.1=-Dderby.system.home="data/derby" wrapper.java.additional.2=-Dderby.storage.fileSyncTransactionLog=true wrapper.java.additional.3=-Dcom.sun.management.jmxremote wrapper.java.additional.4=-Dclassworlds.conf="conf/servicemix.conf" wrapper.java.additional.5=-Dservicemix.home="." wrapper.java.additional.6=-Djava.endorsed.dirs="lib/endorsed" wrapper.java.additional.7=-server wrapper.java.additional.8=-Dorg.apache.cxf.Logger=org.apache.cxf.common.logging.Log4jLogger # Initial Java Heap Size (in MB) wrapper.java.initmemory=64 # Maximum Java Heap Size (in MB) wrapper.java.maxmemory=512 # Application parameters. Add parameters as needed starting from 1 #wrapper.app.parameter.1= wrapper.startup.timeout=20 #******************************************************************** # Wrapper Logging Properties #******************************************************************** # Format of output for the console. (See docs for formats) wrapper.console.format=PM # Log Level for console output. (See docs for log levels) wrapper.console.loglevel=DEBUG # Log file to use for wrapper output logging. wrapper.logfile=logs/wrapper.log # Format of output for the log file. (See docs for formats) wrapper.logfile.format=LPTM # Log Level for log file output. (See docs for log levels) wrapper.logfile.loglevel=DEBUG # Maximum size that the log file will be allowed to grow to before # the log is rolled. Size is specified in bytes. The default value # of 0, disables log rolling. May abbreviate with the 'k' (kb) or # 'm' (mb) suffix. For example: 10m = 10 megabytes. wrapper.logfile.maxsize=0 # Maximum number of rolled log files which will be allowed before old # files are deleted. The default value of 0 implies no limit. wrapper.logfile.maxfiles=0 # Log Level for sys/event log output. (See docs for log levels) wrapper.syslog.loglevel=NONE #******************************************************************** # Wrapper Windows Properties #******************************************************************** # Title to use when running as a console wrapper.console.title=ServiceMix Service Bus #******************************************************************** # Wrapper Windows NT/2000/XP Service Properties #******************************************************************** # WARNING - Do not modify any of these properties when an application # using this configuration file has been installed as a service. # Please uninstall the service before modifying this section. The # service can then be reinstalled. # Name of the service wrapper.ntservice.name=ServiceMix # Display name of the service wrapper.ntservice.displayname=ServiceMix Service Bus # Description of the service wrapper.ntservice.description=ServiceMix Service Bus # Service dependencies. Add dependencies as needed starting from 1 #wrapper.ntservice.dependency.1= # Mode in which the service is installed. AUTO_START or DEMAND_START wrapper.ntservice.starttype=AUTO_START # Allow the service to interact with the desktop. wrapper.ntservice.interactive=false
Now, the following batch files need to be created. These files are to be saved into the base ServiceMix directory.
Batch File |
Purpose |
---|---|
ServiceMix-Service.bat |
Used to run ServiceMix in a console window. If there is a Windows Service that is already running, the batch file will not allow the console version to begin |
Install-ServiceMix-As-Service.bat |
installs ServiceMix as a Windows Service) |
UnInstall-ServiceMix-As-Service.bat |
removes ServiceMix from the Windows Service manager |
Start-ServiceMix-Service.bat |
Starts the ServiceMix Windows Service. ServiceMix must be previously installed as a Windows Service |
Stop-ServiceMix-Service.bat |
Stops the ServiceMix Windows Service. ServiceMix must be previously installed as a Windows Service |
@echo off setlocal rem Copyright (c) 1999, 2006 Tanuki Software Inc. rem rem Java Service Wrapper general startup script rem rem rem Resolve the real path of the wrapper.exe rem For non NT systems, the _REALPATH and _WRAPPER_CONF values rem can be hard-coded below and the following test removed. rem if "%OS%"=="Windows_NT" goto nt echo This script only works with NT-based versions of Windows. goto :eof :nt rem rem Find the application home. rem rem %~dp0 is location of current script under NT set _REALPATH=%~dp0 rem Decide on the wrapper binary. set _WRAPPER_BASE=wrapper set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe if exist "%_WRAPPER_EXE%" goto conf echo Unable to locate a Wrapper executable using any of the following names: echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe echo %_REALPATH%%_WRAPPER_BASE%.exe pause goto :eof rem rem Find the wrapper.conf rem :conf set _WRAPPER_CONF="%~f1" if not %_WRAPPER_CONF%=="" goto startup set _WRAPPER_CONF="%_REALPATH%conf\wrapper.conf" rem rem Start the Wrapper rem :startup "%_WRAPPER_EXE%" -q %_WRAPPER_CONF% set /a EL = "%ERRORLEVEL% & 2" IF %EL%==2 GOTO :alreadyrunning "%_WRAPPER_EXE%" -c %_WRAPPER_CONF% if not errorlevel 1 goto :eof pause goto :eof :alreadyrunning echo . echo Application is already running as a service. echo . echo Please stop the service before running the echo application in console mode pause goto :eof
@echo off setlocal rem Copyright (c) 1999, 2006 Tanuki Software Inc. rem rem Java Service Wrapper general NT service install script rem if "%OS%"=="Windows_NT" goto nt echo This script only works with NT-based versions of Windows. goto :eof :nt rem rem Find the application home. rem rem %~dp0 is location of current script under NT set _REALPATH=%~dp0 rem Decide on the wrapper binary. set _WRAPPER_BASE=wrapper set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe if exist "%_WRAPPER_EXE%" goto conf echo Unable to locate a Wrapper executable using any of the following names: echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe echo %_REALPATH%%_WRAPPER_BASE%.exe pause goto :eof rem rem Find the wrapper.conf rem :conf set _WRAPPER_CONF="%~f1" if not %_WRAPPER_CONF%=="" goto startup set _WRAPPER_CONF="%_REALPATH%conf\wrapper.conf" rem rem Install the Wrapper as an NT service. rem :startup "%_WRAPPER_EXE%" -i %_WRAPPER_CONF% if not errorlevel 1 goto :eof pause
@echo off setlocal rem Copyright (c) 1999, 2006 Tanuki Software Inc. rem rem Java Service Wrapper general NT service uninstall script rem if "%OS%"=="Windows_NT" goto nt echo This script only works with NT-based versions of Windows. goto :eof :nt rem rem Find the application home. rem rem %~dp0 is location of current script under NT set _REALPATH=%~dp0 rem Decide on the wrapper binary. set _WRAPPER_BASE=wrapper set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe if exist "%_WRAPPER_EXE%" goto conf echo Unable to locate a Wrapper executable using any of the following names: echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe echo %_REALPATH%%_WRAPPER_BASE%.exe pause goto :eof rem rem Find the wrapper.conf rem :conf set _WRAPPER_CONF="%~f1" if not %_WRAPPER_CONF%=="" goto startup set _WRAPPER_CONF="%_REALPATH%conf\wrapper.conf" rem rem Uninstall the Wrapper as an NT service. rem :startup "%_WRAPPER_EXE%" -r %_WRAPPER_CONF% if not errorlevel 1 goto :eof pause
@echo off setlocal rem Copyright (c) 1999, 2006 Tanuki Software Inc. rem rem Java Service Wrapper general NT service start script rem if "%OS%"=="Windows_NT" goto nt echo This script only works with NT-based versions of Windows. goto :eof :nt rem rem Find the application home. rem rem %~dp0 is location of current script under NT set _REALPATH=%~dp0 rem Decide on the wrapper binary. set _WRAPPER_BASE=wrapper set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe if exist "%_WRAPPER_EXE%" goto conf echo Unable to locate a Wrapper executable using any of the following names: echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe echo %_REALPATH%%_WRAPPER_BASE%.exe pause goto :eof rem rem Find the wrapper.conf rem :conf set _WRAPPER_CONF="%~f1" if not %_WRAPPER_CONF%=="" goto startup set _WRAPPER_CONF="%_REALPATH%conf\wrapper.conf" rem rem Start the Wrapper NT service. rem :startup "%_WRAPPER_EXE%" -t %_WRAPPER_CONF% if not errorlevel 1 goto :eof pause
@echo off setlocal rem Copyright (c) 1999, 2006 Tanuki Software Inc. rem rem Java Service Wrapper general NT service stop script rem if "%OS%"=="Windows_NT" goto nt echo This script only works with NT-based versions of Windows. goto :eof :nt rem rem Find the application home. rem rem %~dp0 is location of current script under NT set _REALPATH=%~dp0 rem Decide on the wrapper binary. set _WRAPPER_BASE=wrapper set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe if exist "%_WRAPPER_EXE%" goto conf set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe if exist "%_WRAPPER_EXE%" goto conf echo Unable to locate a Wrapper executable using any of the following names: echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe echo %_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe echo %_REALPATH%%_WRAPPER_BASE%.exe pause goto :eof rem rem Find the wrapper.conf rem :conf set _WRAPPER_CONF="%~f1" if not %_WRAPPER_CONF%=="" goto startup set _WRAPPER_CONF="%_REALPATH%conf\wrapper.conf" rem rem Stop the Wrapper NT service. rem :startup "%_WRAPPER_EXE%" -p %_WRAPPER_CONF% if not errorlevel 1 goto :eof pause
One benefit of using the above strategy to 'Servic-ize' your installation of ServiceMix is that, if needed, the original servicemix.bat batch file in the bin directory is still usable.
Also, although I have not tested it, the Java Service Wrapper should also work on *nix based systems to start ServiceMix as a deamon.