You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2014/02/12 20:50:29 UTC

svn commit: r1567742 - /tomcat/tc7.0.x/trunk/bin/service.bat

Author: markt
Date: Wed Feb 12 19:50:29 2014
New Revision: 1567742

URL: http://svn.apache.org/r1567742
Log:
Fix a secondary issue identified in https://issues.apache.org/bugzilla/show_bug.cgi?id=56079
Install the service with a single call to the .exe rather than three calls.

Modified:
    tomcat/tc7.0.x/trunk/bin/service.bat

Modified: tomcat/tc7.0.x/trunk/bin/service.bat
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/bin/service.bat?rev=1567742&r1=1567741&r2=1567742&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/bin/service.bat (original)
+++ tomcat/tc7.0.x/trunk/bin/service.bat Wed Feb 12 19:50:29 2014
@@ -137,9 +137,20 @@ rem Set the client jvm from JAVA_HOME
 set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
 if exist "%PR_JVM%" goto foundJvm
 set PR_JVM=auto
+set PR_STDOUTPUT=auto
+set PR_STDERROR=auto
 :foundJvm
 echo Using JVM:              "%PR_JVM%"
-"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop
+"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
+    --StartClass org.apache.catalina.startup.Bootstrap ^
+    --StopClass org.apache.catalina.startup.Bootstrap ^
+    --StartParams start ^
+    --StopParams stop ^
+    --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%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" ^
+    --StartMode jvm ^
+    --StopMode jvm ^
+    --JvmMs 128 ^
+    --JvmMx 256
 if not errorlevel 1 goto installed
 echo Failed installing '%SERVICE_NAME%' service
 goto end
@@ -151,13 +162,6 @@ set PR_INSTALL=
 set PR_LOGPATH=
 set PR_CLASSPATH=
 set PR_JVM=
-rem Set extra parameters
-"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm
-rem More extra parameters
-set "PR_LOGPATH=%CATALINA_BASE%\logs"
-set PR_STDOUTPUT=auto
-set PR_STDERROR=auto
-"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256
 echo The service '%SERVICE_NAME%' has been installed.
 
 :end



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1567742 - /tomcat/tc7.0.x/trunk/bin/service.bat

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-02-15 23:03 GMT+04:00 Konstantin Preißer <kp...@apache.org>:
> Hi,
>
>> -----Original Message-----
>> From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
>> Sent: Saturday, February 15, 2014 6:50 PM
>> To: Tomcat Developers List
>> Subject: Re: svn commit: r1567742 - /tomcat/tc7.0.x/trunk/bin/service.bat
>>
>> 2014-02-12 23:50 GMT+04:00  <ma...@apache.org>:
>> > Author: markt
>> > Date: Wed Feb 12 19:50:29 2014
>> > New Revision: 1567742
>> >
>> > URL: http://svn.apache.org/r1567742
>> > Log:
>> > Fix a secondary issue identified in
>> https://issues.apache.org/bugzilla/show_bug.cgi?id=56079
>> > Install the service with a single call to the .exe rather than three calls.
>> >
>>
>> Major:
>> ---------
>> service.bat install  is broken by this change on Windows 7.
>>
>> The symptom is that none of "PR_" variables set to pass classpath, jvm
>> etc. to  Tomcat7.exe
>> appear to have any effect.
>>
>> It is odd. I suspect that it might be a bug in commons daemon procrun.
>
>
> Hmm, I think the problem here is another one. Actually, I think this change didn't break service.bat. When opening a cmd.exe as administrator and use "service install", it still works with 8.0.4 and 7.0.52.
>
> I think the problem is, that when a process is elevated by UAC (from normal user-rights to admin-rights), the environment variables of the parent process are lost. My guess would be that the process cannot be a "real" child process of the parent when it has different access rights so it cannot inherit the environment variables (although SysInternals Process Explorer still shows the process as child of cmd.exe).
>
> I verified this by creating a simple C# application that outputs an environment variable:
>
>             Console.WriteLine("%TEST%: " + Environment.GetEnvironmentVariable("TEST"));
>             Console.WriteLine("%ComSpec%: " + Environment.GetEnvironmentVariable("ComSpec"));
>
> When changing the app's manifest so that it requires administrative access:
>     <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
> Then when starting this .exe from cmd.exe, environment variables set in cmd.exe ("TEST", "ComSpec") were lost.
>
> The problem happens also with earlier versions of Tomcat, when running service.bat from an non-elevated cmd.exe and then clicking "Yes" on the UAC dialog. (E.g., the service in the service explorer then shows "Tomcat8" instead of "Apache Tomcat 8").
> Unfortunately, when writing the comment for bug 56079, I did not check if the service is installed correctly, but only check for the message displayed in the console like "The service Tomcat7 has been installed successfully", so I did not notice the problem.
>
> I think currently the only way to correctly install Tomcat as a service when using service.bat is to run cmd.exe as administrator.
>

Thank you.
You are right.

If I create a batch file like the following:
[[[
D:
cd \temp.2014-02-15\apache-tomcat-7.0.52\bin
set "JAVA_HOME=C:\Program Files (x86)\Java\jdk1.7.0_51"
call service.bat install
pause
]]]

and use "Launch as administrator" on it in Explorer,  the service is
installed successfully,

(With exception stdoutput/stderror settings. Those remain as empty.
The service starts successfully, but stdout/stderr are not caught to a
file).

So this did not work earlier either. The only regression in 7.0.52 is
stderr/stdout one.
There were several reports on users@. This explains it.

I'll add this to Bugzilla.

> If it is possible to provide the values as arguments instead of environment variables, then I think it should work when running service.bat from a non-elevated cmd.exe

Agreed.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


RE: svn commit: r1567742 - /tomcat/tc7.0.x/trunk/bin/service.bat

Posted by Konstantin Preißer <kp...@apache.org>.
Hi,

> -----Original Message-----
> From: Konstantin Kolinko [mailto:knst.kolinko@gmail.com]
> Sent: Saturday, February 15, 2014 6:50 PM
> To: Tomcat Developers List
> Subject: Re: svn commit: r1567742 - /tomcat/tc7.0.x/trunk/bin/service.bat
> 
> 2014-02-12 23:50 GMT+04:00  <ma...@apache.org>:
> > Author: markt
> > Date: Wed Feb 12 19:50:29 2014
> > New Revision: 1567742
> >
> > URL: http://svn.apache.org/r1567742
> > Log:
> > Fix a secondary issue identified in
> https://issues.apache.org/bugzilla/show_bug.cgi?id=56079
> > Install the service with a single call to the .exe rather than three calls.
> >
> 
> Major:
> ---------
> service.bat install  is broken by this change on Windows 7.
> 
> The symptom is that none of "PR_" variables set to pass classpath, jvm
> etc. to  Tomcat7.exe
> appear to have any effect.
> 
> It is odd. I suspect that it might be a bug in commons daemon procrun.


Hmm, I think the problem here is another one. Actually, I think this change didn't break service.bat. When opening a cmd.exe as administrator and use "service install", it still works with 8.0.4 and 7.0.52.

I think the problem is, that when a process is elevated by UAC (from normal user-rights to admin-rights), the environment variables of the parent process are lost. My guess would be that the process cannot be a "real" child process of the parent when it has different access rights so it cannot inherit the environment variables (although SysInternals Process Explorer still shows the process as child of cmd.exe).

I verified this by creating a simple C# application that outputs an environment variable:

            Console.WriteLine("%TEST%: " + Environment.GetEnvironmentVariable("TEST"));
            Console.WriteLine("%ComSpec%: " + Environment.GetEnvironmentVariable("ComSpec"));

When changing the app's manifest so that it requires administrative access:
    <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
Then when starting this .exe from cmd.exe, environment variables set in cmd.exe ("TEST", "ComSpec") were lost.

The problem happens also with earlier versions of Tomcat, when running service.bat from an non-elevated cmd.exe and then clicking "Yes" on the UAC dialog. (E.g., the service in the service explorer then shows "Tomcat8" instead of "Apache Tomcat 8").
Unfortunately, when writing the comment for bug 56079, I did not check if the service is installed correctly, but only check for the message displayed in the console like "The service Tomcat7 has been installed successfully", so I did not notice the problem.

I think currently the only way to correctly install Tomcat as a service when using service.bat is to run cmd.exe as administrator.

If it is possible to provide the values as arguments instead of environment variables, then I think it should work when running service.bat from a non-elevated cmd.exe


Regards,
Konstantin Preißer

> 
> Does "install" command (//IS) in procrun recognize the environment
> variables?
> 
> A workaround should be to pass those values as arguments instead of
> environment variables.
> 
> Documentation:
> http://commons.apache.org/proper/commons-daemon/procrun.html
> 
> Steps to reproduce
> --------------------------
> With 7.0.52, on Windows 7
> 
> 1. Set JAVA_HOME  (I was using 7u51 JDK)
> 
> 2. Remove installed service, if any
> service.bat remove
> An UAC prompt appears, reply OK.
> 
> 3. Install
> service.bat install
> An UAC prompt appears, reply OK.
> 
> 4. Run tomcat7w.exe
> An UAC prompt appears, reply OK.
> 
> Switch to "Java" page.
> Actual:  Java Classpath field is empty
> Expected: Java Classpath field has bootstrap.jar etc.
> 
> As a result, the service cannot be started.
> ("Start" command succeeds, but JVM exits immediately).
> 
> Minor:
> ---------
> 1) There is no changelog entry for this in Tomcat 7. (There is one in 8.0.4).
> 
> 2) The following lines:
> 
> > +set PR_STDOUTPUT=auto
> > +set PR_STDERROR=auto
> 
> They have no effect, because execution jumps around because of "goto
> foundJvm"
> 
> 3) The "Clear the environment variables." part
> is not executed on failure and does not clear PR_STDOUTPUT,
> PR_STDERROR variables.
> 
> Actually, it is not needed at all and can be removed,  thanks to
> "setlocal" call earlier.
> It was needed earlier when Tomcat7.exe was called several times in
> succession with different sets of variables.
> 
> Best regards,
> Konstantin Kolinko
> 
> > Modified:
> >     tomcat/tc7.0.x/trunk/bin/service.bat
> >
> > Modified: tomcat/tc7.0.x/trunk/bin/service.bat
> > URL:
> http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/bin/service.bat?rev=15
> 67742&r1=1567741&r2=1567742&view=diff
> >
> ==========================================================
> ====================
> > --- tomcat/tc7.0.x/trunk/bin/service.bat (original)
> > +++ tomcat/tc7.0.x/trunk/bin/service.bat Wed Feb 12 19:50:29 2014
> > @@ -137,9 +137,20 @@ rem Set the client jvm from JAVA_HOME
> >  set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
> >  if exist "%PR_JVM%" goto foundJvm
> >  set PR_JVM=auto
> > +set PR_STDOUTPUT=auto
> > +set PR_STDERROR=auto
> >  :foundJvm
> >  echo Using JVM:              "%PR_JVM%"
> > -"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass
> org.apache.catalina.startup.Bootstrap --StopClass
> org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop
> > +"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
> > +    --StartClass org.apache.catalina.startup.Bootstrap ^
> > +    --StopClass org.apache.catalina.startup.Bootstrap ^
> > +    --StartParams start ^
> > +    --StopParams stop ^
> > +    --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-
> Dcatalina.home=%CATALINA_HOME%;-
> Djava.endorsed.dirs=%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" ^
> > +    --StartMode jvm ^
> > +    --StopMode jvm ^
> > +    --JvmMs 128 ^
> > +    --JvmMx 256
> >  if not errorlevel 1 goto installed
> >  echo Failed installing '%SERVICE_NAME%' service
> >  goto end
> > @@ -151,13 +162,6 @@ set PR_INSTALL=
> >  set PR_LOGPATH=
> >  set PR_CLASSPATH=
> >  set PR_JVM=
> > -rem Set extra parameters
> > -"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-
> Dcatalina.base=%CATALINA_BASE%;-
> Dcatalina.home=%CATALINA_HOME%;-
> Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --
> StopMode jvm
> > -rem More extra parameters
> > -set "PR_LOGPATH=%CATALINA_BASE%\logs"
> > -set PR_STDOUTPUT=auto
> > -set PR_STDERROR=auto
> > -"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-
> Djava.io.tmpdir=%CATALINA_BASE%\temp;-
> Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-
> Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --
> JvmMs 128 --JvmMx 256
> >  echo The service '%SERVICE_NAME%' has been installed.
> >
> >  :end
> >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: dev-help@tomcat.apache.org
> >
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1567742 - /tomcat/tc7.0.x/trunk/bin/service.bat

Posted by Konstantin Kolinko <kn...@gmail.com>.
2014-02-12 23:50 GMT+04:00  <ma...@apache.org>:
> Author: markt
> Date: Wed Feb 12 19:50:29 2014
> New Revision: 1567742
>
> URL: http://svn.apache.org/r1567742
> Log:
> Fix a secondary issue identified in https://issues.apache.org/bugzilla/show_bug.cgi?id=56079
> Install the service with a single call to the .exe rather than three calls.
>

Major:
---------
service.bat install  is broken by this change on Windows 7.

The symptom is that none of "PR_" variables set to pass classpath, jvm
etc. to  Tomcat7.exe
appear to have any effect.

It is odd. I suspect that it might be a bug in commons daemon procrun.

Does "install" command (//IS) in procrun recognize the environment variables?

A workaround should be to pass those values as arguments instead of
environment variables.

Documentation:
http://commons.apache.org/proper/commons-daemon/procrun.html

Steps to reproduce
--------------------------
With 7.0.52, on Windows 7

1. Set JAVA_HOME  (I was using 7u51 JDK)

2. Remove installed service, if any
service.bat remove
An UAC prompt appears, reply OK.

3. Install
service.bat install
An UAC prompt appears, reply OK.

4. Run tomcat7w.exe
An UAC prompt appears, reply OK.

Switch to "Java" page.
Actual:  Java Classpath field is empty
Expected: Java Classpath field has bootstrap.jar etc.

As a result, the service cannot be started.
("Start" command succeeds, but JVM exits immediately).

Minor:
---------
1) There is no changelog entry for this in Tomcat 7. (There is one in 8.0.4).

2) The following lines:

> +set PR_STDOUTPUT=auto
> +set PR_STDERROR=auto

They have no effect, because execution jumps around because of "goto foundJvm"

3) The "Clear the environment variables." part
is not executed on failure and does not clear PR_STDOUTPUT,
PR_STDERROR variables.

Actually, it is not needed at all and can be removed,  thanks to
"setlocal" call earlier.
It was needed earlier when Tomcat7.exe was called several times in
succession with different sets of variables.

Best regards,
Konstantin Kolinko

> Modified:
>     tomcat/tc7.0.x/trunk/bin/service.bat
>
> Modified: tomcat/tc7.0.x/trunk/bin/service.bat
> URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/bin/service.bat?rev=1567742&r1=1567741&r2=1567742&view=diff
> ==============================================================================
> --- tomcat/tc7.0.x/trunk/bin/service.bat (original)
> +++ tomcat/tc7.0.x/trunk/bin/service.bat Wed Feb 12 19:50:29 2014
> @@ -137,9 +137,20 @@ rem Set the client jvm from JAVA_HOME
>  set "PR_JVM=%JRE_HOME%\bin\client\jvm.dll"
>  if exist "%PR_JVM%" goto foundJvm
>  set PR_JVM=auto
> +set PR_STDOUTPUT=auto
> +set PR_STDERROR=auto
>  :foundJvm
>  echo Using JVM:              "%PR_JVM%"
> -"%EXECUTABLE%" //IS//%SERVICE_NAME% --StartClass org.apache.catalina.startup.Bootstrap --StopClass org.apache.catalina.startup.Bootstrap --StartParams start --StopParams stop
> +"%EXECUTABLE%" //IS//%SERVICE_NAME% ^
> +    --StartClass org.apache.catalina.startup.Bootstrap ^
> +    --StopClass org.apache.catalina.startup.Bootstrap ^
> +    --StartParams start ^
> +    --StopParams stop ^
> +    --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%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" ^
> +    --StartMode jvm ^
> +    --StopMode jvm ^
> +    --JvmMs 128 ^
> +    --JvmMx 256
>  if not errorlevel 1 goto installed
>  echo Failed installing '%SERVICE_NAME%' service
>  goto end
> @@ -151,13 +162,6 @@ set PR_INSTALL=
>  set PR_LOGPATH=
>  set PR_CLASSPATH=
>  set PR_JVM=
> -rem Set extra parameters
> -"%EXECUTABLE%" //US//%SERVICE_NAME% --JvmOptions "-Dcatalina.base=%CATALINA_BASE%;-Dcatalina.home=%CATALINA_HOME%;-Djava.endorsed.dirs=%CATALINA_HOME%\endorsed" --StartMode jvm --StopMode jvm
> -rem More extra parameters
> -set "PR_LOGPATH=%CATALINA_BASE%\logs"
> -set PR_STDOUTPUT=auto
> -set PR_STDERROR=auto
> -"%EXECUTABLE%" //US//%SERVICE_NAME% ++JvmOptions "-Djava.io.tmpdir=%CATALINA_BASE%\temp;-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager;-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties" --JvmMs 128 --JvmMx 256
>  echo The service '%SERVICE_NAME%' has been installed.
>
>  :end
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: dev-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org