8

Post Tomcat 8.0.53, when I install Tomcat (9.0.30 or 8.5.50) and install it as service (Using service.bat), it gets installed but with "Log on" as "Local Service" instead of "Local System account".

This can be seen under services in windows.

Apache Service Apache Service Properties, Log On tab

Because of this, when I run the service, the application is not able to read a file.

If I manually go to services, open properties for my service, then change the Log on as "Local System" and save, everything works perfectly.

  1. Why does this happen for tomcat versions post 8.0.53?
  2. How can tomcat be installed so that it has "Log on as" set to "LocalSystem" instead of "LocalService"? I am not able to do it with additional parameters like --User and --Password as mentioned in the 8.5 and 9.0 documentation.
zeevb
  • 103
  • 6
pullCommitRun
  • 373
  • 6
  • 18

3 Answers3

10

This appears to be a result of these issues: 55969 and 63310. The update to Commons Daemon 1.2.0 seems to be the cause, and it does not appear that one can modify this setting during installation.

However, it can be set to Local System afterwards from an administrator command prompt with the following command:

sc config Tomcat8 obj=LocalSystem
Brown
  • 1,132
  • 1
  • 13
  • 33
  • 1
    Given workaround works fine! I just didn't get time to answer my question. Also, Since there was only one file which was an issue while reading it, i changed the file permission using icacls/cacls windows command and then the application worked fine even with tomcat running as window's service with LocalService account. – pullCommitRun Feb 04 '20 at 09:27
  • 1
    Glad it worked for you as well! Thanks for marking this as the answer. I uncovered a bit more information, so I'll update my answer. – Brown Feb 05 '20 at 15:22
  • Any ideas why modifying this through Command Prompt doesn't change the data shown in the GUI from Tomcat#w.exe? If I change it via CMD, I see the change in the sc qc queries, but not the GUI itself - is a reboot required? – k1dfr0std Mar 30 '23 at 15:16
1

Hoping Google will pick this up so the next user can find this 3 hours quicker...

For me this error manifested itself with a Chrome console message:

net::ERR_CONTENT_LENGTH_MISMATCH 200

...and this error was only raised after my html called some css using relative path.

As shown above, the problem was solved by changing the windows service to a local system account which can interact with desktop.

Does any stackoverflow superuser know how to get that message into the question title above? That's what it Chrome shows when Tomcat "is not able to read a file".

Paul Cuddihy
  • 477
  • 6
  • 12
0

Set the --ServiceUser parameter with LocalSystem value to the service installation executable in the bin\service.bat.

"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
--Description "Apache Tomcat 8.5.91 Server - https://tomcat.apache.org/" ^
--DisplayName "Apache Tomcat 8.5 %SERVICE_NAME%" ^
--Install "%EXECUTABLE%" ^
--LogPath "%CATALINA_BASE%\logs" ^
--StdOutput auto ^
--StdError auto ^
--Classpath "%CLASSPATH%" ^
--Jvm "%JVM%" ^
--StartMode jvm ^
--StopMode jvm ^
--StartPath "%CATALINA_HOME%" ^
--StopPath "%CATALINA_HOME%" ^
--StartClass org.apache.catalina.startup.Bootstrap ^
--StopClass org.apache.catalina.startup.Bootstrap ^
--StartParams start ^
--StopParams stop ^
--JvmOptions "-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_BASE%;-D%ENDORSED_PROP%=%CATALINA_HOME%\endorsed;-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties;%JvmArgs%" ^
--JvmOptions9 "--add-opens=java.base/java.lang=ALL-UNNAMED#--add-opens=java.base/java.io=ALL-UNNAMED#--add-opens=java.base/java.util=ALL-UNNAMED#--add-opens=java.base/java.util.concurrent=ALL-UNNAMED#--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED" ^
--Startup "%SERVICE_STARTUP_MODE%" ^
--JvmMs "%JvmMs%" ^
--JvmMx "%JvmMx%" ^
--ServiceUser "LocalSystem"

This will make the service to be installed with the LocalSystem account privileges. See Tomcat v8.5 user guide Windows Service How-To for more details.

Bruce
  • 647
  • 2
  • 12
  • 30