I need to run an Apache Derby Server as a service so Derby starts together with the machine it is installed on.
Now I tried three solutions -based on my research- to create such a service but none of them are either feasible or generate errors.
Use the Java Service Wrapper: this is not feasible because they only offer a 30 day trial for free.
Use the Windows Server Manager (SrvMgr.exe) to create a service as described here: http://www.vogella.com/tutorials/ApacheDerby/article.html. This seems to work because I created a service that shows up in the Windows Registry, can be started/stopped via the Services panel and something is using
http://localhost:1527
the default address for the Derby server. However if I try to connect to the database via eclipse (luna) or the console I get an error:Could not connect to DerbyPersistenceDeploy. Error creating SQL Model Connection connection to DerbyPersistenceDeploy. (Error: DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J) DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J Error creating JDBC Connection connection to DerbyPersistenceDeploy. (Error: DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J) DERBY SQL error: ERRORCODE: 40000, SQLSTATE: XJ041, SQLERRMC: Failed to create database 'persistence', see the next exception for details.::SQLSTATE: XBM0J
Here is an image of the Registry entry of the service:
The last approach I tied was to use Apache procrun (http://commons.apache.org/proper/commons-daemon/procrun.html). I worked my way through this tutorial (http://joerglenhard.wordpress.com/2012/05/29/build-windows-service-from-java-application-with-procrun/) and I managed to get the example service running. However as I tried to adapt the script posted in the tuorial I got the following error (from the log file):
[2014-07-21 16:52:20] [error] [ 3708] Method 'static void start(String[])' not found in Class org/apache/derby/drda/NetworkServerControl [2014-07-21 16:52:20] [error] [ 6228] Failed to start Java [2014-07-21 16:52:20] [error] [ 6228] ServiceStart returned 4 [2014-07-21 16:52:20] [error] [ 6228] Commons Daemon procrun failed with exit value: 3 (Failed to run service as console application)
Here is my adapted script to create the webservice:
set SERVICE_NAME=DerbyPersistenceService set PR_INSTALL=D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe REM Service log configuration set PR_LOGPREFIX=%SERVICE_NAME% set PR_LOGPATH=D:\04_server\derby\DerbyServiceScript\logs set PR_STDOUTPUT=D:\04_server\derby\DerbyServiceScript\logs\stdout.txt set PR_STDERROR=D:\04_server\derby\DerbyServiceScript\logs\stderr.txt set PR_LOGLEVEL=Error REM Path to java installation set PR_JVM=C:\Program Files (x86)\Java\jdk1.7.0_65\jre\bin\client\jvm.dll set PR_CLASSPATH=%DERBY_HOME%/lib/derby.jar; %DERBY_HOME%/lib/derbynet.jar; %DERBY_HOME%/lib/derbyclient.jar; %DERBY_HOME%/lib/derbytools.jar REM Startup configuration set PR_STARTUP=auto set PR_STARTMODE=jvm set PR_STARTCLASS=org.apache.derby.drda.NetworkServerControl set PR_STARTPARAM=start set PR_STARTMETHOD=main REM Shutdown configuration set PR_STOPMODE=jvm set PR_STOPCLASS=org.apache.derby.drda.NetworkServerControl set PR_STOPPARAM=shutdown set PR_STOPMETHOD=main REM JVM configuration set PR_JVMMS=256 set PR_JVMMX=1024 set PR_JVMSS=4000 set PR_JVMOPTIONS=-Duser.language=US;-Duser.region=en REM Install service D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe //IS//%SERVICE_NAME%
I assume that this error stems from the fact that the
Startup
- andShutdown-Configurations
are not configured the right way but I have no idea what they should look like.
If someone knows a solution for either approach 2. or 3. I would be very grateful.
Greetings
[edit1:] I edited my Procrun script as Bryan Pendleton suggested.
[edit2:]The Service gives me a new error message:
stderr.txt
:
2014-07-23 16:41:14 Commons Daemon procrun stderr initialized
stdout.txt
:
2014-07-23 16:41:14 Commons Daemon procrun stdout initialized
Wed Jul 23 16:41:14 CEST 2014 : No command given.
Usage: NetworkServerControl <commands>
Commands:
start [-h <host>] [-p <port number>] [-noSecurityManager] [-ssl <ssl mode>]
shutdown [-h <host>][-p <port number>] [-ssl <ssl mode>] [-user <username>] [-password <password>]
ping [-h <host>][-p <port number>] [-ssl <ssl mode>]
sysinfo [-h <host>][-p <port number>] [-ssl <ssl mode>]
runtimeinfo [-h <host>][-p <port number>] [-ssl <ssl mode>]
logconnections { on|off } [-h <host>][-p <port number>] [-ssl <ssl mode>]
maxthreads <max>[-h <host>][-p <port number>] [-ssl <ssl mode>]
timeslice <milliseconds>[-h <host>][-p <port number>] [-ssl <ssl mode>]
trace { on|off } [-s <session id>][-h <host>][-p <port number>] [-ssl <ssl mode>]
tracedirectory <trace directory>[-h <host>][-p <port number>] [-ssl <ssl mode>]
DerbyPersistenceService.2014-07-23.log
is empty.
I think something is not right with the method arguments.
[edit3:]Changed the script so it is a working solution. Many thanks to Bryan Pendleton for helping me with this one.
set SERVICE_NAME=DerbyPersistenceService
set PR_INSTALL=D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe
REM Service log configuration
set PR_LOGPREFIX=%SERVICE_NAME%
set PR_LOGPATH=D:\04_server\derby\DerbyServiceScript\logs
set PR_STDOUTPUT=D:\04_server\derby\DerbyServiceScript\logs\stdout.txt
set PR_STDERROR=D:\04_server\derby\DerbyServiceScript\logs\stderr.txt
set PR_LOGLEVEL=Error
REM Path to java installation
set PR_JVM=C:\Program Files (x86)\Java\jdk1.7.0_65\jre\bin\client\jvm.dll
set PR_CLASSPATH=%DERBY_HOME%/lib/derby.jar;
%DERBY_HOME%/lib/derbynet.jar;
%DERBY_HOME%/lib/derbyclient.jar;
%DERBY_HOME%/lib/derbytools.jar
REM Startup configuration
set PR_STARTUP=auto
set PR_STARTMODE=jvm
set PR_STARTCLASS=org.apache.derby.drda.NetworkServerControl
set PR_STARTPARAMS=start
set PR_STARTMETHOD=main
REM Shutdown configuration
set PR_STOPMODE=jvm
set PR_STOPCLASS=org.apache.derby.drda.NetworkServerControl
set PR_STOPPARAMS=shutdown
set PR_STOPMETHOD=main
REM JVM configuration
set PR_JVMMS=256
set PR_JVMMX=1024
set PR_JVMSS=4000
set PR_JVMOPTIONS=-Duser.language=US;-Duser.region=en
REM Install service
D:\Program-Files\commons-daemon-1.0.15-bin-windows\prunsrv.exe //IS//%SERVICE_NAME%