Windows service installed with Procrun works in //TS mode, but doesn't start as a Windows service saying it "started and then stopped"
Asked Answered
J

4

13

I installed a standard executable jar file as a Windows service by running the following command:

> prunsrv.exe //IS//"My Service" --Install="C:\path-to-prunsrv.exe" --Jvm=auto \
  --Startup=auto --StartMode=jvm --Classpath="C:\path-to-MyService.jar" \
  --StartClass=com.mydomain.MyService

I can now run my program fine in console mode by running the following command (I'm using Java 1.6):

> prunsrv.exe //TS//"My Service"

When I try to start the service through the standard Windows services interface, I get the following error message:

The MyService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs.

There is no output in my application's log file when I attempt to start the service this way. There is also no output in the Window's event log (Windows 7 64-bit). What can I do to try and figure out why this service will not run?

Johen answered 23/5, 2012 at 18:38 Comment(2)
Are you running the service as a 'local user', or as an admin user?Obsecrate
It is set to the default "Local System account" used for other services. I've tried other accounts to no avail.Johen
J
5

Don't use any white-space in the service name!

After many hours of testing and pulling apart Tomcat and duplicating it's bootstrap process, the fix for my problem ended up being that Apache Commons Daemon (Procrun) does not work properly when there is white-space in the name of the Windows service.

It seemingly correctly installs and registers a service with Windows when there are spaces in the service name. The Windows registry entries even look correct. The service even runs in debug (aka TS or console) mode just fine. When run, however, as an actual service launched by Windows it fails if the service was installed with a white-space in the service name.

I sure wish Procrun had some type of log output when it fails! Good logging can make debugging issues like this a snap.

I did need to have multiple words in my service name, so I named my service with one word and changed the name with the "DisplayName" parameter:

> prunsrv.exe //IS//MyService --Install="C:\path-to-prunsrv.exe" --Jvm=auto \
  --Startup=auto --StartMode=jvm --Classpath="C:\path-to-MyService.jar" \
  --StartClass=com.mydomain.MyService --DisplayName="My Service"
Johen answered 25/5, 2012 at 14:14 Comment(0)
H
2

I wanted to give some additional information about what '11101101b' said above. (This is my first post, so please be gentle!)

I was able to get the service to install correctly with spaces in the service name by changing the //IS//MyService part of his command to instead be the following, which I suspect is what he also did. (I apologize if I'm assuming incorrectly.) Notice that the opening double quote is at the beginning of the string rather than at the beginning of the service name.

"//IS//My Service"

As was the case for him, the service installed correctly and looked correct, but it wouldn't start. I was able to get around that by changing the service's ImagePath value data setting in the registry to have the same change for the //RS//My Service part of the command. Therefore, the registry value instead had the following in its data setting:

"//RS//My Service"

Everything seems to be working without any problems.

Hedgepeth answered 23/6, 2014 at 22:42 Comment(1)
Thanks for the follow-up @Hedgepeth That may come in useful.Johen
W
1

This server starts and stops because of reason the task is completed by the service so it would stop automatically. if you have a logic of running long inside it would not stop.

Wavy answered 3/4, 2015 at 13:49 Comment(0)
R
-1

I got same problem ... under my local machine everthing working fine on server the same issue => problem was that Working Path was not set. May its heps someone ... be the force with you

enter image description here

Rutheruthenia answered 8/8, 2019 at 11:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.