This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository

commit 7ac5fc8a59c10e7de1ee6d4b85c1ee797942a1e7
Author: Mark Thomas <>
AuthorDate: Thu Aug 8 13:17:29 2019 +0100

    Align the behaviour of service.bat with the Windows installer and rename
    the executables on installation (and restore on removal).
 bin/service.bat                        | 110 ++++++++++++++++++++++-----------
 webapps/docs/changelog.xml             |   9 +++
 webapps/docs/windows-service-howto.xml |  14 ++++-
 3 files changed, 94 insertions(+), 39 deletions(-)

diff --git a/bin/service.bat b/bin/service.bat
index 5d9e053..6105b15 100755
--- a/bin/service.bat
+++ b/bin/service.bat
@@ -17,7 +17,7 @@ rem limitations under the License.
 rem ---------------------------------------------------------------------------
 rem NT Service Install/Uninstall script
-rem Usage: service.bat install/remove [service_name] [/user username]
+rem Usage: service.bat install/remove [service_name [--no-rename]] [--user 
 rem Options
 rem install                 Install the service using default settings.
@@ -26,7 +26,10 @@ rem
 rem service_name (optional) The name to use for the service. If not specified,
 rem                         Tomcat@VERSION_MAJOR@ is used as the service name.
-rem username (optional)     The name of the OS user to use to install/remove
+rem --no-rename  (optional) Don't rename tomcat@VERSION_MAJOR@.exe and 
tomcat@version_ma...@w.exe to match
+rem                         the non-default service name.
+rem username     (optional) The name of the OS user to use to install/remove
 rem                         the service (not the name of the OS user the
 rem                         service will run as). If not specified, the current
 rem                         user is used.
@@ -35,21 +38,70 @@ rem 
 set "SELF=%~dp0%service.bat"
-rem Guess CATALINA_HOME if not defined
 set "CURRENT_DIR=%cd%"
+rem Parse the arguments
+if "x%1x" == "xx" goto displayUsage
+if "x%1x" == "xx" goto checkEnv
+if "x%1x" == "x/userx" goto runAsUser
+if "x%1x" == "x--userx" goto runAsUser
+if "x%1x" == "xx" goto checkEnv
+if "x%1x" == "x--no-renamex" (
+    set NO_RENAME=%1
+    shift
+if "x%1x" == "xx" goto checkEnv
+goto checkUser
+if "x%1x" == "xx" goto displayUsage
+runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" 
+goto end
+rem Check the environment
+rem Guess CATALINA_HOME if not defined
 if not "%CATALINA_HOME%" == "" goto gotHome
 set "CATALINA_HOME=%cd%"
-if exist "%CATALINA_HOME%\bin\tomcat@VERSION_MAJOR@.exe" goto okHome
+if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" goto okHome
+if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" goto okHome
 rem CD to the upper dir
 cd ..
 set "CATALINA_HOME=%cd%"
-if exist "%CATALINA_HOME%\bin\tomcat@VERSION_MAJOR@.exe" goto okHome
-echo The tomcat@VERSION_MAJOR@.exe was not found...
-echo The CATALINA_HOME environment variable is not defined correctly.
-echo This environment variable is needed to run this program
+if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
+    goto okHome
+if exist "%CATALINA_HOME%\bin\%SERVICE_NAME%.exe" (
+    goto okHome
+    echo The file %DEFAULT_SERVICE_NAME%.exe was not found...
+) else (
+    echo Neither the %DEFAULT_SERVICE_NAME%.exe file nor the 
%SERVICE_NAME%.exe file was found...
+echo Either the CATALINA_HOME environment variable is not defined correctly or
+echo the incorrect service name has been used.
+echo Both the CATALINA_HOME environment variable and the correct service name
+echo are required to run this program.
 goto end
 rem Make sure prerequisite environment variables are set
 if not "%JAVA_HOME%" == "" goto gotJdkHome
 if not "%JRE_HOME%" == "" goto gotJreHome
@@ -81,12 +133,6 @@ if not "%CATALINA_BASE%" == "" goto gotBase
-rem Set default Service name
 rem Java 9 no longer supports the java.endorsed.dirs
 rem system property. Only try to use it if
 rem JAVA_ENDORSED_DIRS was explicitly set
@@ -100,33 +146,14 @@ if not exist "%CATALINA_HOME%\endorsed" goto doneEndorsed
 set ENDORSED_PROP=java.endorsed.dirs
-if "x%1x" == "xx" goto displayUsage
-if "x%1x" == "xx" goto checkServiceCmd
-if "x%1x" == "x/userx" goto runAsUser
-if "x%1x" == "x--userx" goto runAsUser
-if "x%1x" == "xx" goto checkServiceCmd
-goto checkUser
-if "x%1x" == "xx" goto displayUsage
-runas /env /savecred /user:%SERVICE_USER% "%COMSPEC% /K \"%SELF%\" 
-goto end
+rem Process the requested command
 if /i %SERVICE_CMD% == install goto doInstall
 if /i %SERVICE_CMD% == remove goto doRemove
 if /i %SERVICE_CMD% == uninstall goto doRemove
 echo Unknown parameter "%SERVICE_CMD%"
-echo Usage: service.bat install/remove [service_name] [/user username]
+echo Usage: service.bat install/remove [service_name [--no-rename]] [--user 
 goto end
@@ -141,6 +168,10 @@ echo Failed removing '%SERVICE_NAME%' service
 goto end
 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"
 goto end
@@ -169,6 +200,14 @@ if "%SERVICE_STARTUP_MODE%" == "" set 
 if "%JvmMs%" == "" set JvmMs=128
 if "%JvmMx%" == "" set JvmMx=256
+if exist "%CATALINA_HOME%\bin\%DEFAULT_SERVICE_NAME%.exe" (
+    if "x%NO_RENAME%x" == "xx" (
+        rename "%DEFAULT_SERVICE_NAME%.exe" "%SERVICE_NAME%.exe"
+        rename "%DEFAULT_SERVICE_NAME%w.exe" "%SERVICE_NAME%w.exe"
+    )
     --Description "Apache Tomcat @VERSION@ Server -"; ^
     --DisplayName "%DISPLAYNAME%" ^
@@ -198,4 +237,3 @@ goto end
 echo The service '%SERVICE_NAME%' has been installed.
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index d81703c..c2419a7 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -203,6 +203,15 @@
         with Apache Tomcat. (remm)
+        <bug>63285</bug>: Modify <code>service.bat</code> so that when
+        installing a Windows service, by default, it changes the name of the
+        executables used by the Windows service to match the service name. This
+        makes the installation behaviour consistent with the Windows installer.
+        The original executable names will be restored when the Windows service
+        is removed. The renaming can be disabled by using the new
+        <code>--no-rename</code> option after the service name. (markt)
+      </fix>
+      <fix>
         <bug>63567</bug>: Restore the passing of <code>$LOGGING_MANAGER</code>
         to the jvm in <code></code> when calling <code>stop</code>.
diff --git a/webapps/docs/windows-service-howto.xml 
index d3c69b9..b9215f7 100644
--- a/webapps/docs/windows-service-howto.xml
+++ b/webapps/docs/windows-service-howto.xml
@@ -346,9 +346,9 @@ script. If necessary, you can use the <code>/user</code> 
switch to specify
 a user to use for the installation of the service.
-<strong>NOTE:</strong> On Windows Vista or any later operating system with User
-Account Control (UAC) enabled you will be asked for additional privileges
-when 'Tomcat<version-major/>.exe' is launched by the script.<br/>
+<strong>NOTE:</strong> If User Account Control (UAC) is enabled you will be
+asked for additional privileges when 'Tomcat<version-major/>.exe' is launched 
+the script.<br/>
 If you want to pass additional options to service installer as
 <code>PR_*</code> environment variables, you have to either configure them
 globally in OS, or launch the program that sets them with elevated privileges
@@ -367,6 +367,14 @@ service, as displayed in Windows services.</p>
 <source>Install the service named 'MyService'
 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 will be renamed to
+match the chosen service name. To prevent this, use the 
+<source>Install the service named 'MyService' without renaming
+C:\> service.bat install MyService --no-rename</source>
 If using tomcat<version-major/>.exe, you need to use the <b>//IS//</b> 

To unsubscribe, e-mail:
For additional commands, e-mail:

Reply via email to