views:

35

answers:

1

Firstly, I am not at all familiar with windows batch file programing. Recently I am curious about how tomcat sets itself as a windows service using a batch file. I downloaded the service.bat file from tomcat 6. However, I still don't understand some part of it.

I guess this is the line that the batch actually register the exe file to the OS, is it right? Is there any syntax explanation?

"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop

And is this used to remove the service?

"%EXECUTABLE%" //DS//%SERVICE_NAME%

And this is the setting of the parameters?

"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm

Thanks.

+1  A: 

IS - Install Service

DS - Delete Service

US - Update Service

If you want to create your own services in a batch file look into using sc.exe instead. Run it by itself on a command line for help.

The executable you install as a windows service must be implemented as a windows service. If it isn't, you need some wrapper that is an official windows service and runs the target exe. Some commercial examples:

http://www.eltima.com/products/application-as-service/

http://www.firedaemon.com/

I'm surprised I didn't find an open-source/free option. This type of thing could be done in C# in less than 50 lines of code.

Sam
Thanks, it works in adding the .exe file into the list of windows service. However, I cannot run it. The exception "The service did not respond to the start or control request in a timely fashion" pops up. Do you happen to know the solution. I am currently googling for it too.
Winston Chen
@Wing C. Chen, oh, the exe must be a windows service. There are some 3rd party options that provide a windows service which is just a wrapper for other exe's. http://www.firedaemon.com/ or http://www.eltima.com/products/application-as-service/
Sam