Apache daemons procrun prunsrv Windows exe mode not working

Juul Vanparijs picture Juul Vanparijs · Sep 22, 2012 · Viewed 8.8k times · Source

For a few years we've been using Procrun to turn Java apps into Services (and without problems).
We also have some native Windows Executables running as Services. Until now, we used Windows Management Instrumentation (WMI) to define these, but I'm now trying to use Procrun for these native exe's as well... Unfortunately, I can't get the Service to start (or at least to remain running).
The Service seems correctly created; the Prunsrvlog/stdout/stderr don't contain errors; the registry keys, both under Apache/procrun and system/Services seem to be created ok; I can look at the service using either the Windows Services applet or the Prunmgr monitor; but... the Service never shows as started. When I try to manually start the Service from Prunmgr, I get the "... attempting to start" popup for a few seconds, but the Service remains stopped.
When I try to start it from Win Services applet, I additionally get a popup: The service started and stopped. Some services stop automatically if not used".

I found most of the solution myself:
I somehow messed up my native test program, and it was always interacting with the Windows Service Controller... When using Procrun your native program must not (de)register itself with the Windows Service Controller, as this is handled by Procrun itself. After correcting my test service, I could start and stop it using Procrun services.

... But a few questions remain:

  1. I found some hits telling that the serviceName must not contain spaces, but I also (painfully) discovered that the displayName must not contain spaces when using Procrun for native executables. If the displayName contains spaces, the Properties page in the Windows Services applet refuses to open. I've no idea what may the cause of this, and this doesn't apply when using Java applications.

  2. Even if you set the service to autostart (E.g. via set PR_STARTUP=auto), a "native" service is not started when you install it, and it needs an explicit start command (E.g. bin\TestService start) (but the "native" service will auto-start at every reboot)... this again does not apply when wrapping Java apps... these auto-start when they're installed.

And a last bit of advise: when using the set PR_xxx=format to define the parameters for the service, values containing spaces generally must not be quoted... This may go without saying for some of the more experienced folks, but I suffered quite a bit from this :-(

The remainder of this long post is mostly for history (or the rare interested individual)

The code to define the service:

set MY_HOME=c:\program files (x86)\testProgs\
cd /d "%MY_HOME%"
set PR_INSTALL=c:\program files (x86)\testProgs\bin\TestService
set PR_DISPLAYNAME=TestProg_Shared_Memory_Service
set PR_DESCRIPTION=Shared Memory Server for Testing Purposes
set PR_STARTUP=auto
set PR_LOGPATH=c:\program files (x86)\testProgs\logs
set PR_STDOUTPUT=auto
set PR_STDERROR=auto
set PR_STARTMODE=exe
set PR_STARTPATH=c:\program files (x86)\testProgs
set PR_STARTIMAGE=c:\program files (x86)\testProgs\bin\TPShmSrvD.exe
set PR_STARTPARAMS=PORT=9088;PATH=c:\program files (x86)\testProgs
set PR_STOPMODE=exe
set PR_STOPIMAGE=%MY_HOME%bin\TPCommand.exe
set PR_STOPPARAMS=PORT=9088;STOP;SHMSRV
set PR_LOGLEVEL=DEBUG
bin\TestService install

And as I discovered later on, do not forget to add:

bin\TestService start

The results in commons-daemon.log:

[2012-09-22 15:26:32] [debug] ( prunsrv.c:1644) Commons Daemon procrun log initialized
[2012-09-22 15:26:32] [info]  ( prunsrv.c:1648) Commons Daemon procrun (1.0.10.0 32-bit) started
[2012-09-22 15:26:32] [debug] ( prunsrv.c:559 ) Installing service...
[2012-09-22 15:26:32] [info]  ( prunsrv.c:595 ) Service TestService name TestProg_Shared_Memory_Service
[2012-09-22 15:26:32] [debug] ( prunsrv.c:611 ) Setting service description Shared Memory Server for Testing Purposes
[2012-09-22 15:26:32] [info]  ( prunsrv.c:629 ) Service 'TestService' installed
[2012-09-22 15:26:32] [info]  ( prunsrv.c:1729) Commons Daemon procrun finished
[2012-09-22 15:27:00] [debug] ( prunsrv.c:1644) Commons Daemon procrun log initialized
[2012-09-22 15:27:00] [info]  ( prunsrv.c:1648) Commons Daemon procrun (1.0.10.0 32-bit) started
[2012-09-22 15:27:00] [info]  ( prunsrv.c:1561) Running 'TestService' Service...
[2012-09-22 15:27:00] [debug] ( prunsrv.c:1345) Inside ServiceMain...
[2012-09-22 15:27:00] [info]  ( prunsrv.c:1089) Starting service...
[2012-09-22 15:27:00] [info]  ( prunsrv.c:1244) Service started in 15 ms.
[2012-09-22 15:27:00] [debug] ( prunsrv.c:1496) Waiting for worker to finish...
[2012-09-22 15:27:01] [debug] ( prunsrv.c:1501) Worker finished.
[2012-09-22 15:27:01] [debug] ( prunsrv.c:1524) Waiting for all threads to exit
[2012-09-22 15:27:01] [debug] ( prunsrv.c:1528) JVM destroyed.
[2012-09-22 15:27:01] [info]  ( prunsrv.c:1563) Run service finished.
[2012-09-22 15:27:01] [info]  ( prunsrv.c:1729) Commons Daemon procrun finished

The TestService stdout/stderr both just contain a single line saying "stdout/stderr initialised"
The Registry keys under ProcRun:

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\TestService]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\TestService\Parameters]

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\TestService\Parameters\Log]
"Path"="c:\\program files (x86)\\testProgs\\logs"
"Level"="DEBUG"
"StdError"="auto"
"StdOutput"="auto"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\TestService\Parameters\Start]
"Image"="c:\\program files (x86)\\testProgs\\bin\\TPShmSrvD.exe"
"WorkingPath"="c:\\program files (x86)\\testProgs"
"Params"=hex(7):50,00,4f,00,52,00,54,00,3d,00,39,00,30,00,38,00,38,00,00,00,50,\
  00,41,00,54,00,48,00,3d,00,63,00,3a,00,5c,00,70,00,72,00,6f,00,67,00,72,00,\
  61,00,6d,00,20,00,66,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,36,\
  00,29,00,5c,00,74,00,65,00,73,00,74,00,50,00,72,00,6f,00,67,00,73,00,00,00,\
  00,00
"Mode"="exe"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Apache Software Foundation\Procrun 2.0\TestService\Parameters\Stop]
"Image"="c:\\program files (x86)\\testProgs\\bin\\TPCommand.exe"
"Params"=hex(7):50,00,4f,00,52,00,54,00,3d,00,39,00,30,00,38,00,38,00,00,00,53,\
  00,54,00,4f,00,50,00,00,00,53,00,48,00,4d,00,53,00,52,00,56,00,00,00,00,00
"Mode"="exe"

And under SYSTEM\Services:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TestService]
"Type"=dword:00000010
"Start"=dword:00000002
"ErrorControl"=dword:00000001
"ImagePath"=hex(2):22,00,63,00,3a,00,5c,00,70,00,72,00,6f,00,67,00,72,00,61,00,\
  6d,00,20,00,66,00,69,00,6c,00,65,00,73,00,20,00,28,00,78,00,38,00,36,00,29,\
  00,5c,00,74,00,65,00,73,00,74,00,50,00,72,00,6f,00,67,00,73,00,5c,00,62,00,\
  69,00,6e,00,5c,00,54,00,65,00,73,00,74,00,53,00,65,00,72,00,76,00,69,00,63,\
  00,65,00,22,00,20,00,2f,00,2f,00,52,00,53,00,2f,00,2f,00,54,00,65,00,73,00,\
  74,00,53,00,65,00,72,00,76,00,69,00,63,00,65,00,00,00
"DisplayName"="TestProg_Shared_Memory_Service"
"DependOnService"=hex(7):54,00,63,00,70,00,69,00,70,00,00,00,41,00,66,00,64,00,\
  00,00,00,00
"WOW64"=dword:00000001
"ObjectName"="LocalSystem"
"Description"="Shared Memory Server for Testing Purposes"

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\TestService\Parameters]

I've tried just about everything I can think of, but I can't get the Service to run :-(
Two more remarks:
1. I originally had spaces in the DisplayName. Until I replaced them with underscores, I was not able to open the Properties page in Windows Services applet!!!

2. The native exe has code in place to register with the Windows Service Controller (mainly to enable clean termination when Windows is being shut down). This code gets executed if the name of the executable ends with a "d.exe" (case insensitive). I tried using both forms (i.e. TPShmSrvD.exe and TPShmSrv.exe) for the StartImage, but to no avail...

Any help will be greatly appreciated,

Juul

Answer

Vijay picture Vijay · Dec 16, 2015

This may not be final answer but run below commands

c:\Temp>prunsrv.exe //IS//VIJAY

create service of name VIJAY

c:\temp\prunmgr.exe //ES//VIJAY

start UI to edit service VIJAY

Its easy to edit paramaters from UI