This example shows how to use SvcBatch to run Apache Tomcat as a Windows service.
Download the latest SvcBatch release
and put svcbatch.exe
into your tomcat/bin
directory.
The SvcBatch executable can be shared between multiple Tomcat instances.
Put svcbatch.exe
into the desired directory and modify
your service create scripts to set the work directory using -w
command line option that is unique for each different instance.
Inside the Tomcat directory there are two batch files that provide the complete solution to run and manage Apache Tomcat as windows service.
Put winservice and eventually
setenv batch files
together with svcbatch.exe
into your tomcat/bin
directory.
winservice is a batch file that can be used to manage service instead typing multiple commands.
> winservice.bat create
That's it! Now, just type ...
> winservice.bat start
The setenv batch file (or the existing one) can be used to modify any environment variables needed. For example, you can set the JAVA_HOME or JRE_HOME or any other environment variable to the location different then the one defined for the account under which the service is running.
Instead above example, you can create your own service by following the next few steps.
Create a service by opening command prompt with Administrator
privileges inside your tomcat/bin
directory
> svcbatch create Tomcat --displayName "Apache Tomcat" -h .. bin\catalina.bat run"
Optionally you can add description ...
> svcbatch config Tomcat --description "Apache Tomcat Service"
And ...
> svcbatch config Tomcat --start=auto
Check the Managing Services documentation for detailed description how to use the SvcBatch to create and manage services
To manually start the service use:
> svcbatch start Tomcat
Or ..
> sc start Tomcat
Stop the service by entering
> svcbatch stop Tomcat
Delete the service by entering
> svcbatch delete Tomcat
-
Notice
This command will fail if the service is running. In that case stop the service, and call this command again.