When a Tomcat service on Windows Server 2019 restarts automatically after being killed, it is typically due to the Windows Service Control Manager's recovery settings or a watchdog script monitoring the process. To stop this behavior, you must configure the service's failure actions to "Take No Action" and verify that no external scripts are triggering automatic restarts.
Understanding Automatic Restart Mechanisms
The phenomenon where a service respawns itself immediately after termination can be confusing for administrators who expect a manual stop command to persist. On Windows Server 2019, the primary culprit is usually the built-in Recovery tab within the Service properties. By default, many services are configured to restart on failure to ensure high availability. However, if an administrator manually stops or kills the process, the system might interpret this as a transient failure and trigger a restart policy.
Another common cause involves third-party monitoring tools or custom batch files designed to keep critical applications running. These scripts often use loops to check if the java.exe process associated with Tomcat is active. If the process disappears, the script launches it again. This behavior is intentional in production environments but problematic during maintenance windows or debugging sessions.
Configuring Service Recovery Settings
The most direct way to prevent automatic restarts is to modify the recovery options for the Tomcat service. This setting controls what happens when the service fails or is stopped unexpectedly. Follow these steps to adjust the configuration:
- Open the Services management console by pressing
Win + R, typingservices.msc, and hitting Enter. - Locate the Apache Tomcat service in the list. It may be named differently depending on your installation version.
- Right-click the service and select Properties.
- Navigate to the Recovery tab at the top of the window.
- You will see three dropdown menus labeled First failure, Second failure, and Subsequent failures.
- Change all three options from "Restart the Service" to "Take No Action".
- Click Apply and then OK to save the changes.
After applying these changes, the Windows Service Control Manager will no longer attempt to restart the service if it crashes or is manually terminated. Note that this change affects only the specific instance of the Tomcat service selected.
Checking for Watchdog Scripts
If modifying the recovery settings does not stop the auto-start behavior, the issue likely lies outside the Windows Service Control Manager. You should investigate scheduled tasks or startup scripts that might be launching Tomcat.
Check the Task Scheduler for any tasks related to Tomcat. Look for triggers such as "At system startup" or "On event" logs. Additionally, inspect the Windows Registry under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run for entries that might invoke a batch file containing the Tomcat start command.
If you are using a wrapper like Apache Commons Daemon (procrun), ensure that the wrapper configuration file (service.xml or similar) does not contain auto-restart directives. Some wrappers have built-in health checks that respawn the JVM if it becomes unresponsive.
Verifying Process Termination
To confirm that the service has been fully stopped, use the Task Manager or Command Prompt. Open a command prompt as Administrator and run the following command to identify any lingering Java processes:
tasklist /fi "imagename eq java.exe"
If Java processes remain, they may be orphaned threads or child processes that were not cleaned up properly. Use the taskkill command with the /F flag to force terminate them, but exercise caution as this may leave temporary files behind.
taskkill /f /im java.exe
Always ensure that you have stopped the service via the proper channels before forcing process termination to avoid data corruption in your web applications.
Related Resources
If you are experiencing issues with user permissions affecting service startup, you might find relevant information in our guide on Windows Credentials Deleted for specific user. Additionally, for managing local development environments, our article on Access my locally hosted website from another computer outside my network without a domain name provides useful networking tips.
Frequently Asked Questions
Why does my Tomcat service restart even after I set it to manual?
Setting the startup type to manual prevents Windows from starting the service at boot, but it does not control recovery actions after a crash. You must also configure the Recovery tab to take no action to prevent automatic restarts after failures.
Can I disable auto-restart for all Tomcat instances globally?
No, recovery settings are configured per-service instance. Each Tomcat installation registered as a Windows service requires individual configuration in the Services console to change its failure response behavior.
What happens if I choose "Restart the Service" in the Recovery tab?
If you select "Restart the Service," Windows will attempt to restart the Tomcat service automatically after a specified delay (default is 1 minute) whenever it detects a failure or unexpected termination.
How do I know if a batch file is restarting Tomcat?
You can monitor the System Event Log for application events or use Process Monitor to track when cmd.exe or bat files execute. Check the Task Scheduler history for recent task executions linked to your Tomcat directory.
Is it safe to force kill the Java process?
Force killing the Java process can lead to corrupted session data or incomplete transactions. It is safer to use the bin/shutdown.bat script provided with Tomcat to gracefully stop the service before terminating any remaining processes.