Bug 56143 - Allow "service.bat install" to be used in an non-UAC cmd.exe session
Summary: Allow "service.bat install" to be used in an non-UAC cmd.exe session
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Integration (show other bugs)
Version: 7.0.50
Hardware: PC All
: P2 enhancement (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-16 13:16 UTC by Konstantin Kolinko
Modified: 2018-05-12 17:43 UTC (History)
1 user (show)



Attachments
tomcat7 (deleted)
2018-05-12 17:20 UTC, jerson viveros
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Konstantin Kolinko 2014-02-16 13:16:15 UTC
If you use a Microsoft Windows OS that has UAC and use service.bat script to install Tomcat as a service, you have to first launch command console (cmd.exe) in elevated privileges mode ("Run as administrator") and then call "service.bat install" from there.

This requirement is mentioned in Tomcat documentation:
http://tomcat.apache.org/tomcat-7.0-doc/windows-service-howto.html#Installing_services

[quote]
NOTE: On Windows Vista or any other operating system with User Account Control (UAC) you must either disable UAC or right-click on cmd.exe and select "Run as administrator" in order to run this script. If UAC is enabled being logged on with an Administrator account is not sufficient. 
[/quote]



If you forget to launch cmd.exe in that mode and just run "service.bat install",  with the current Tomcat versions (6.0.39, 7.0.50, 8.0.3) you will be prompted 3 times by UAC [3], but the service will be installed incorrectly.

With r1565781 / r1567742 (7.0.52) this was improved and you will be prompted by UAC only once, but still the service will be installed incorrectly.


The cause for this behaviour is that install command in service.bat script uses environment variables (such as PR_CLASSPATH) to pass parameters to service installer (prunsrv).[1] Apparently, when a child application is launched with elevated privileges it does not inherit environment variables from its parent. [2]

The consequence is that a number of crucial settings in the installed service will be blank. For example, its classpath and its log path will be blank.

As a result, an attempt to launch such service will fail shortly and silently, as Tomcat bootstrap classes are not found and logging is not configured either.

(There will be some logs in %SystemRoot%\system32\LogFiles\Apache  though).


A workaround is to fix such configuration by using service configuration application (tomcat7w.exe) to configure missing options.


I hope that this can be solved by changing service.bat so that all necessary options are passed as command-line arguments instead of variables.

For reference:
[1] Apache Commons Daemon documentation
http://commons.apache.org/proper/commons-daemon/procrun.html

[2] "Re: r1567742" thread on dev mailing list
http://tomcat.markmail.org/thread/tjmwxc5vb5ut4zuq

[3] Bug 56079
https://issues.apache.org/bugzilla/show_bug.cgi?id=56079#c6
Comment 1 Konstantin Kolinko 2014-02-16 16:12:27 UTC
Fixed in Tomcat 8 by r1568779, docs updated by r1568786. Will be in 8.0.4.
Comment 2 Konstantin Kolinko 2014-02-17 11:24:22 UTC
Fixed in Tomcat 7 by r1568920 and will be in 7.0.53.
Comment 3 Konstantin Kolinko 2014-04-23 12:50:11 UTC
Fixed in Tomcat 6 with r1589390 , will be in 6.0.40.
Comment 4 Abdul Wahid 2014-06-25 14:41:15 UTC
Hi Konstantin,

I am getting permission issue only for tomcat service while installing TOMCAT 7 on windows 2000 server.

I logged into the server with Administrator privileges. 
Please update with your feedback.

Thanks,
Abdul Wahid
Comment 5 Konstantin Kolinko 2014-06-25 22:33:14 UTC
(In reply to Abdul Wahid from comment #4)

You are asking on a different topic. Your question cannot be answered here.
Comment 6 Mark Thomas 2018-05-12 17:43:42 UTC
The content of attachment 35932 [details] has been deleted for the following reason:

Not relevant. Potential malware.