Recently I came across an issue where I was not able to start a service:

My Service (service) service is starting.
My Service (service) service could not be started.

A service specific error occurred: 0.

More help is available by typing NET HELPMSG 3547.

Command exited with status 2

This is not a very helpful message, so we try to figure out what it means.

net helpmsg 3547

A service specific error occurred: ***.

To figure out the problem we must enable log messages. To do this we use prunsrv to update the service definition.

prunsrv //US/my.service --LogLevel=Debug --LogJniMessages=1 --LogPath=%dev%\service.log

Then, next time we run we the service we will be able to see the problem.

[2013-08-29 21:08:01] [info]  Running 'my.service' Service...
[2013-08-29 21:08:01] [info]  Starting service...
[2013-08-29 21:08:01] [error] Failed creating java 
[2013-08-29 21:08:01] [error] ServiceStart returned 1
[2013-08-29 21:08:01] [info]  Run service finished.

Success!

We can see the the issue is with Java. Basically, procrun does not know where the JVM is. The default places it looks on Windows are usually the Windows registry keys \\HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment and \\HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Development Kit. Some basic Java installations do not set these registry keys. To resolve this issue, we have to show it where the JVM is. To do this, we have a few options:

  • Install a distribution of Java that sets Windows registry keys and environment variables.
  • Update the service definition and tell it where JAVA_HOME
  • Update the service definition to point it straight to jvm.dll

We can quickly glance over at the documentation to see the flags: http://commons.apache.org/proper/commons-daemon/procrun.html. Then, to update the service we simply run:

prunsrv.exe //US/my.service --JavaHome %JAVA_HOME% --Jvm %JREDIR%\bin\client\jvm.dll

You will notice that in my example I am using both methods. And that's all there is to it!