This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new bc7243ddb1 Fix BZ 70262 - fix --rename option for service.bat
bc7243ddb1 is described below
commit bc7243ddb1f1492cb188b64f4d1b763f5d3db64b
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Oct 21 20:47:57 2026 +0100
Fix BZ 70262 - fix --rename option for service.bat
Based on PR #1095 provided by StrongOx
---
bin/service.bat | 60 ++++++++++++++++++++++++++++++----
webapps/docs/changelog.xml | 8 +++++
webapps/docs/windows-service-howto.xml | 5 ++-
3 files changed, 65 insertions(+), 8 deletions(-)
diff --git a/bin/service.bat b/bin/service.bat
index 0a153ae5cf..afb6ab48d0 100755
--- a/bin/service.bat
+++ b/bin/service.bat
@@ -41,6 +41,7 @@ set "SELF=%~dp0%service.bat"
set DEFAULT_SERVICE_NAME=Tomcat@VERSION_MAJOR@
set SERVICE_NAME=%DEFAULT_SERVICE_NAME%
+set "RENAMED_SERVICE_EXE="
set "CURRENT_DIR=%cd%"
@@ -181,9 +182,28 @@ echo Failed removing '%SERVICE_NAME%' service
exit /b 1
:removed
echo The service '%SERVICE_NAME%' has been removed
-if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
- rename "%SERVICE_NAME%.exe" "%DEFAULT_SERVICE_NAME%.exe"
- rename "%SERVICE_NAME%w.exe" "%DEFAULT_SERVICE_NAME%w.exe"
+rem Restore the default executable names only when install --rename changed
them.
+rem The default executable is not a renamed copy, and renaming a file to
itself fails.
+rem The source path is required: rename looks up a bare file name in the
current directory, not in CATALINA_HOME\bin.
+if /I not "%SERVICE_NAME%" == "%DEFAULT_SERVICE_NAME%" (
+ if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
+ rename "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
"%DEFAULT_SERVICE_NAME%.exe"
+ if errorlevel 1 (
+ echo Failed to rename "%SERVICE_NAME%.exe" to
"%DEFAULT_SERVICE_NAME%.exe"
+ exit /b 1
+ )
+ set "RENAMED_SERVICE_EXE=1"
+ )
+ if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%w.exe" (
+ rename "%CATALINA_HOME%\bin\%SERVICE_NAME%w.exe"
"%DEFAULT_SERVICE_NAME%w.exe"
+ if errorlevel 1 (
+ echo Failed to rename "%SERVICE_NAME%w.exe" to
"%DEFAULT_SERVICE_NAME%w.exe"
+ if defined RENAMED_SERVICE_EXE (
+ rename "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe"
"%SERVICE_NAME%.exe"
+ )
+ exit /b 1
+ )
+ )
)
exit /b 0
@@ -213,11 +233,37 @@ if "%SERVICE_STARTUP_MODE%" == "" set
SERVICE_STARTUP_MODE=manual
if "%JvmMs%" == "" set JvmMs=128
if "%JvmMx%" == "" set JvmMx=256
-if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
+rem Rename using the full source path. A bare file name is resolved against
+rem the current directory, so "install service_name --rename" failed unless
+rem it was started from CATALINA_HOME\bin. The new name must be a file name
+rem only. Skip when the requested name is already the default: renaming a
+rem file to itself fails, and there is nothing to rename. If the default
+rem executable is already absent, a previous --rename left the service name
+rem in place and install continues with that file.
+if /I not "%SERVICE_NAME%" == "%DEFAULT_SERVICE_NAME%" (
if "x%RENAME%x" == "x--renamex" (
- rename "%DEFAULT_SERVICE_NAME%.exe" "%SERVICE_NAME%.exe"
- rename "%DEFAULT_SERVICE_NAME%w.exe" "%SERVICE_NAME%w.exe"
- set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
+ if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
+ if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
+ echo The file "%SERVICE_NAME%.exe" already exists. The
executables were not renamed.
+ exit /b 1
+ )
+ if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%w.exe" (
+ echo The file "%SERVICE_NAME%w.exe" already exists. The
executables were not renamed.
+ exit /b 1
+ )
+ rename "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe"
"%SERVICE_NAME%.exe"
+ if errorlevel 1 (
+ echo Failed to rename "%DEFAULT_SERVICE_NAME%.exe" to
"%SERVICE_NAME%.exe"
+ exit /b 1
+ )
+ rename "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%w.exe"
"%SERVICE_NAME%w.exe"
+ if errorlevel 1 (
+ echo Failed to rename "%DEFAULT_SERVICE_NAME%w.exe" to
"%SERVICE_NAME%w.exe"
+ rename "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
"%DEFAULT_SERVICE_NAME%.exe"
+ exit /b 1
+ )
+ set "EXECUTABLE=%CATALINA_HOME%\bin\%SERVICE_NAME%.exe"
+ )
)
)
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index be07fb5285..5f3079de75 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -9054,6 +9054,14 @@
Update the packaged version of the Tomcat Native Library to 1.2.30.
Also
update the minimum recommended version to 1.2.30. (markt)
</update>
+ <fix>
+ <bug>70262</bug>: Fix <code>service.bat</code> so <code>install
+ <name> --rename</code> renames the Windows service executables in
+ <code>CATALINA_HOME\bin</code>. <code>remove</code> now restores the
+ default executable names only when the service name differs from the
+ default. Based on pull request <pr>1095</pr> provided by StrongOx.
+ (markt)
+ </fix>
</changelog>
</subsection>
</section>
diff --git a/webapps/docs/windows-service-howto.xml
b/webapps/docs/windows-service-howto.xml
index e0409a061b..8f8117ccaf 100644
--- a/webapps/docs/windows-service-howto.xml
+++ b/webapps/docs/windows-service-howto.xml
@@ -467,7 +467,7 @@ C:\> service.bat install MyService</source>
<p>When installing the service with a non-default name,
tomcat<version-major/>.exe and tomcat<version-major/>w.exe may be renamed to
match the chosen service name. To do this, use the <code>--rename</code>
-option.</p>
+option. The install will fail if either renamed file already exists.</p>
<source>Install the service named 'MyService' with renaming
C:\> service.bat install MyService --rename</source>
@@ -514,6 +514,9 @@ C:\> tomcat<version-major/>
//DS//Tomcat<version-major/></source>
<source>Remove the service named 'MyService'
C:\> tomcat<version-major/> //DS//MyService</source>
+<p>If a renamed service is removed with <code>service.bat remove</code>, the
+executables are restored to their default names on remove.</p>
+
</section>
<section name="Debugging services">
<p>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]