Transferred from: http://wiki.jikexueyuan.com/project/tomcat/windows-service.html
Tomcat8 is a service application that enables Tomcat 8 to be run as a Windows service.
Tomcat Monitoring App
tomcat8w is a GUI application that monitors and configures the Tomcat service.
The available command-line options are:
es// |
Edit service Configuration |
This is the default action. If no other option is provided, it is called. But the executable has not been renamed to Servicenamew.exe. |
ms// |
Monitoring Services |
Place the icon in the system tray. |
Command-line arguments
The command line instruction format is://xx//servicename.
The available command-line options are:
ts// |
Run the service as a console app |
The default action. If there is no other option, it is called. ServiceName is the name of the executable without the suffix exe, which is Tomcat8. |
rs// |
Running the service |
Can only be called by Service Manager |
ss// |
Stop Service |
|
us// |
Update Service Parameters |
|
is// |
Installation Services |
|
ds// |
Delete Service |
If the service is running, stop the service |
command-line formal parameters
Each command parameter has a prefix --
. If the command line prefix is ++
, the value is appended to the existing option. If the environment variable and the command-line parameter are the same, but the prefix is PR_
, it takes precedence. Like what:
set PR_CLASSPATH=xx.jar
It is equivalent to taking the following as a command-line parameter:
--Classpath=xx.jar
formal parameter name |
default |
Description |
--Description |
- |
Service Name Description (maximum 1024 characters) |
--DisplayName |
Service Name |
Service Display Name |
--Install |
Procrun.exe//rs//servicename |
Install image |
--Starup |
Manual |
There are two types of service startup modes:auto or manual |
++DependsOn |
- |
A set of other services on which the service relies. # ; separating dependent services with or characters |
++Environment |
- |
A set of environment variables provided to the service using the key = value form. Use # ; the or characters to separate dependent environment variables. If you need to use or character in a value # ; , the entire value must be closed in single quotation marks. |
--User |
- |
The user account that is used to run the executable file. is used only for StarMode java or exe values, and allows the application to operate as a service under an account without logonasservice privileges. |
--Password |
- |
--User the user account password that is set by the formal parameter. |
--JavaHome |
Java_home |
Set a java_home that differs from the environment variable of the same name |
--Jvm |
Auto |
You can use Auto(that is, look for the JVM from the Windows registry), or specify the full path to Jvm.dll . You can use environment variable extensions here. |
++JvmOptions |
-xrs |
A set of options passed into the JVM in the format of- D or- x. # ; These options are delimited by or characters (cannot be used in exe mode). |
--Classpath |
- |
Set Java classpath (not for exe mode) |
--JvmMs |
- |
The initial memory pool capacity, measured in megabytes. cannot be used in exe mode |
--JvmMx |
- |
The maximum capacity of the memory pool, measured in megabytes. cannot be used in exe mode |
--JvmSs |
- |
The thread stack capacity, measured in kilobytes. cannot be used in exe mode |
--StartMode |
- |
The value is one of the JVM,java,exe . The meanings of these patterns are:
- Start Java in the jvm--process. Dependent Jvm.dll, see --JVM Parameters Related description
- java--is similar to EXE, but it automatically uses the default Java executable file. That's%java_home%\bin\java.exe. Make sure the java_home is set correctly, or use--javahome to provide the correct location. If none is set, Procrun will look for the default JDK (not the JRE) from the registry
- exe--running an image in standalone process mode
|
--StartImage |
- |
Run the executable file. Only available in exe mode |
--StartPath |
- |
The working path of the start image executable file |
--StartClass |
Main |
The class that contains the startup method. For JVM and java mode, not for exe mode |
--StartMethod |
Main |
If the method name is different, use the main |
++StartParams |
- |
StartImage StartClass A set of parameters passed in or. Separates parameters with # or ; characters. |
--StopMode |
- |
The value is one of the JVM,java,exe . More detailed description See --startmode |
--StopImage |
- |
An executable file that runs under the Stop service signal. Only available in exe mode |
--StopPath |
- |
The working path of the executable file that stopped the image. Not applicable to JVM mode |
--StopClass |
Main |
Class for the Stop service signal. For JVM and Java classes |
--StopMethod |
Main |
If the method name is different, use the main |
++StopParams |
- |
A set of parameters passed into the Stopimage or Stopclass. Use # or ; character to separate formal parameters |
--StopTimeout |
No timeouts |
The number of seconds to use for Procrun waiting for the service to gracefully end. |
--LogPath |
%systemroot%\system32\logfiles\apache |
Defines the log path. Create the path if necessary. |
--LogPrefix |
Commons-daemon |
Defines the service log file name prefix. The log file is created at the path defined by LogPath with the suffix.YEAR-MONTH-DAY.log |
--LogLevel |
Info |
Defines the log level. Value is one of the following values:Error,Info,Warn , or Debug. (Case sensitive) |
--StdOutput |
- |
The standard output file name of the redirect. If autois specified, the file is created at the path defined by LogPath, in the form of a filename:service-stdout. Year-month-day.log |
--StdError |
- |
The standard error file name of the redirect. If autois specified, the file is created at the path defined by LogPath, in the form of a filename:service-stderr. Year-month-day.log |
--PidFile |
- |
Defines the file name of the process ID that is running. The actual files are created in the LogPath directory. |
Installation Services
The safest way to manually install a service is to use the provided service.bat script. Administrator privileges are required to run the script. In order to install the service, you can /user
specify a user if necessary.
Note : If the user Account Control feature is turned on in Windows Vista or another version of the updated Windows operating system, when the script starts Tomcat8.exe, the Uac,user Additional privileges are required for the system. If you want to pass in additional options for the service installer, such as PR_*
environment variables, you must globally configure them on the system, or start related programs, and use more advanced privileges to set them, such as: Right-click Cmd.exe and select "Run as Administrator"; in Windows 8 (or later) or Windows Server 2012 (or later) system, you can also open an advanced command prompt (elevated command prompt) for the current directory by tapping the File menu in File Explorer. See question 56143 for details.
Install the service named ‘Tomcat8‘C:\> service.bat install
There is also a 2nd optional parameter that lets you specify the service name, as shown by the Windows service.
Install the service named ‘MyService‘C:\> service.bat install MyService
If you use Tomcat8.exe, you need to use the //is// parameter.
Install the service named ‘Tomcat8‘C:\> tomcat8 //IS//Tomcat8 --DisplayName="Apache Tomcat 8" C:\> --Install="C:\Program Files\Tomcat\bin\tomcat8.exe" --Jvm=auto C:\> --StartMode=jvm --StopMode=jvm C:\> --StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start C:\> --StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop
Update Service
To update the service parameters, you need to use the //us// parameter.
Update the service named ‘Tomcat8‘C:\> tomcat8 //US//Tomcat8 --Description="Apache Tomcat Server - http://tomcat.apache.org/ " C:\> --Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar
If you want to specify an optional name for the service, you need to do the following:
Update the service named ‘MyService‘C:\> tomcat8 //US//MyService --Description="Apache Tomcat Server - http://tomcat.apache.org/ " C:\> --Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar
Delete Service
To delete a service, you use the //ds// parameter. If the service is running, it will be stopped and then deleted.
Remove the service named ‘Tomcat8‘C:\> tomcat8 //DS//Tomcat8
The following are the ways to specify an optional name for a service:
Remove the service named ‘MyService‘C:\> tomcat8 //DS//MyService
Commissioning Services
To run the service in console mode, you need to use the //ts// parameter. Close the service by pressing CTRL + C or ctrl+break. If Tomcat8.exe is renamed to Testservice.exe, then the command pattern will be executed by default only if the Testservice.exe is executed.
Run the service named ‘Tomcat8‘ in console modeC:\> tomcat8 //TS//Tomcat8 [additional arguments]Or simply execute:C:\> tomcat8
Multiple instances
Tomcat supports installing multiple instances. A Tomcat installation can have multiple instances, which can run on different ip/port combinations, or run in multiple Tomcat versions, one or more instances per version, running on different ip/port combinations.
The folder for each instance should have the following directory structure:
- Conf
- Logs
- Temp
- WebApps
- Work
At a minimum, the Conf directory should contain CATALINA_HOME\conf\
a copy of the following files. Any files that have not been copied or edited will be obtained directly from the CATALINA_HOME\conf
. For example, the CATALINA_BASE\conf
file in will overwrite CATALINA_HOME\conf
the default file.
You must edit Catalina_base\conf\server.xml to specify a unique ip/port for the instance to listen to. Locate the included <Connector port="8080" ...
line of code, add an Address property, and (or) update the port number to specify a unique ip/port combination.
To install an instance, first set the CATALINA_HOME environment variable to the TOMCAT installation directory name. Then create a second environment variable, catalina_base, and point it to the instance folder. The last Run service install
command specifies the service name.
set CATALINA_HOME=c:\tomcat_8set CATALINA_BASE=c:\tomcat_8\instances\instance1service install instance1
To modify the service settings, you need to run tomcat8w//es//instance1.
For additional instances, create an additional instance folder, update CATALINA_BASE
the environment variables, and then install the service again.
set CATALINA_BASE=c:\tomcat_8\instances\instance2service install instance2
Tomcat Service App