Re: Defining environment variables for a webapp ?

2021-04-27 Thread Christopher Schultz

Nirjan,

On 4/26/21 14:19, Niranjan Rao wrote:

On 4/14/21 5:29 AM, Rony G. Flatscher (Apache) wrote:

A JVM
AFAIK would not honor changes to the environment after it got started


A serious question. Apologies for selective selection from the response.

Are there any operating systems where change in environment is 
automatically reflected in child process?


That would be a fairly chaotic system. I don't know of any that do this 
kind of thing.



My understanding was, processes always inherit parent environment and
have no way of knowing what changed.
A copy of the parent environment is made into the child process, which 
diverges from that point forward.


The reason JVMs "would not honor changes to the environment after it got 
started" is because most components that configure based upon envirnment 
variables (or system properties for that matter) only check them when 
first initialized. If you change an environment variable in a process 
(whether from the inside or the outside), it only changes behavior of 
the variable's value is directly-checked periodically instead of "just 
once at startup."


If you managed to spawn a process with different parent based on your 
operating system, then you might see new values, but most of the 
spawn/exec calls (regardless of language of implmentation) inherit the 
exact same environment variables. Some calls do allow you to setup the 
environment variables for child process but struggling to figure out 
where grandparent process informed parent about environment change which 
can be sent to grandchild.


I don't believe any of that can happen, at least not in theway you 
describe. Of course, IPC does exist and you *can* send data between 
processes, so a grantparent process could theoretically tell the 
grandchild process "hey you should set FOO=bar" but the grandchild 
process would have to support that kind of IPC and agree to make the 
change. The gp process can't just reach-in and change the environment.


-chris

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Defining environment variables for a webapp ?

2021-04-27 Thread Rony G. Flatscher (Apache)
Niranjan:

one correction:

On 27.04.2021 15:05, Rony G. Flatscher (Apache) wrote:
> ("heyhey.bat" is executed in a subprocess with a new environment such that 
> its PATH value is
> unchanged!). 

the above statement is wrong, the current environment is inherited with ooRexx' 
ADDRESS instruction
to run commands, sorry, should have double-checked before posting! :(

---rony


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Defining environment variables for a webapp ?

2021-04-27 Thread Rony G. Flatscher (Apache)
On 26.04.2021 20:19, Niranjan Rao wrote:
> On 4/14/21 5:29 AM, Rony G. Flatscher (Apache) wrote:
>> A JVM
>> AFAIK would not honor changes to the environment after it got started
>
> A serious question. Apologies for selective selection from the response.
>
> Are there any operating systems where change in environment is automatically 
> reflected in child
> process? My understanding was, processes always inherit parent environment 
> and have no way of
> knowing what changed.
>
> If you managed to spawn a process with different parent based on your 
> operating system, then you
> might see new values, but most of the spawn/exec calls (regardless of 
> language of implmentation)
> inherit the exact same environment variables. Some calls do allow you to 
> setup the environment
> variables for child process but struggling to figure out where grandparent 
> process informed parent
> about environment change which can be sent to grandchild.

Well, it depends what one does, e.g. spawning a new process is different than 
e.g. changing PATH in
the same process and then relying on the new value for PATH to take effect when 
looking for programs
to run/execute.

An example (Windows, ooRexx):

test.rex ... an ooRexx script that uses Rexx to find "subdir\hey.rex" and 
uses Windows to find
"subdir\heyhey.bat", both depend on PATH (which gets changed in the running 
program and takes
effect as can be seen by the output below); failure is shown with frownies, 
success with smileys :)

subdir\hey.rex ... an ooRexx script displaying the invocation information 
(operating system, how
invoked, fully qualified path to this program) and the current dir

subdir\heyhey.bat ... a batch file displaying some environment variable 
('windir')

Here the output of running "test.rex":

G:\test\orx\env>test.rex
1a) testcall():
:-( | not found!
1b) testcallbat():
'heyhey.bat' is not recognized as an internal or external command,
operable program or batch file.
:-( | not found! | RC=1

... about to add 'G:\test\orx\env\subdir' to PATH ...

2a) testcall():
--> hey.rex: parse source s: [WindowsNT SUBROUTINE 
G:\test\orx\env\subdir\hey.rex]
--> hey.rex: directory()   : [G:\test\orx\env]
:-) | ok!
2b) testcallbat():
*** heyhey.bat: just arrived ***
*** heyhey.bat: windir=C:\WINDOWS ***
*** heyhey.bat: about to return ***
:-) | RC=0

As long as PATH does not contain the "subdir" directory neither "hey.rex" nor 
"heyhey.bat" (this
even causes an error message) are found by Rexx or Windows, cf. 1a) and 1b 
(displays the return code
next to the frownie) above. Once the "subdir" directory gets added in the 
running program (in the
same process) and both programs are found by Rexx and Windows as can be seen by 
the output 2a) and
2b) ("heyhey.bat" is executed in a subprocess with a new environment such that 
its PATH value is
unchanged!).

HTH,

---rony

P.S.: For the record the three files:

subdir\hey.rex:

#!/usr/bin/env rexx
parse source s -- get invocation information
say "--> hey.rex:" "parse source s: ["s"]"   -- show invocation 
information
say "--> hey.rex:" "directory()   : ["directory()"]" -- show current 
directory

subdir\heyhey.bat:

@echo off
echo *** heyhey.bat: just arrived ***
echo *** heyhey.bat: windir=%windir% ***
echo *** heyhey.bat: about to return ***

test.rex:

#!/usr/bin/env rexx
say "1a) testcall():"   -- call a Rexx program
say testCall()
say "1b) testcallbat():"
res=testcallbat()   -- invoke a command
say res
say

newDir=directory()"\subdir"
say "... about to add '"newDir"' to PATH ..."
   -- define new value for PATH
newValue=value('PATH', ,"environment")";"newDir
oldValue=value('PATH', newValue, "environment")   -- change PATH value
say

say "2a) testcall():"   -- call a Rexx program
say testCall()
say "2b) testcallbat():"   -- invoke a command
res=testcallbat()   -- invoke a command
say res

::routine testcall   -- call another Rexx program
  signal on syntax   -- if syntax exception then jump to label "syntax:"
  call hey.rex   -- call the Rexx program, PATH gets searched
  return ":-) | ok!"-- everything went fine, return a smiley
syntax:  -- label
  return ":-( | not found!"   -- return frownie

::routine testcallbat -- call a Windows batch file
  address system "heyhey.bat" -- let Window search and execute the command
  if rc=0 then return ":-) | RC="rc -- if return code is 0 return smiley
  return ":-( | not found! | RC="rc   -- return code indicates 
problem, return frownie






Re: Defining environment variables for a webapp ?

2021-04-26 Thread Niranjan Rao

On 4/14/21 5:29 AM, Rony G. Flatscher (Apache) wrote:

A JVM
AFAIK would not honor changes to the environment after it got started


A serious question. Apologies for selective selection from the response.

Are there any operating systems where change in environment is 
automatically reflected in child process? My understanding was, 
processes always inherit parent environment and have no way of knowing 
what changed.



If you managed to spawn a process with different parent based on your 
operating system, then you might see new values, but most of the 
spawn/exec calls (regardless of language of implmentation) inherit the 
exact same environment variables. Some calls do allow you to setup the 
environment variables for child process but struggling to figure out 
where grandparent process informed parent about environment change which 
can be sent to grandchild.



Regards,


Niranjan


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Defining environment variables for a webapp ?

2021-04-14 Thread Rony G. Flatscher (Apache)
Martynas,

On 14.04.2021 14:20, Martynas Jusevičius wrote:
> you might want to look into containerizing your webapps. We use an
> XSLT stylesheet (invoked by the entrypoint script) that transforms env
> params into context.xml params:
> https://github.com/AtomGraph/LinkedDataHub/blob/master/platform/context.xsl

Thank you very much!

If I understood Mark correctly, the environment variable values need to be set 
in the Tomcat process
before Tomcat starts.

The aim would be to change the environment for the webapps, i.e. in a running 
Tomcat instance. A JVM
AFAIK would not honor changes to the environment after it got started, but 
thought it possible that
through some magic :) by the Tomcat developers this could be achieved for 
webapps. The CGI solution
works with a new environment as a new (relative expensive) process gets created 
through Java for
which all these aspects could be set.

---rony

> On Wed, Apr 14, 2021 at 2:16 PM Rony G. Flatscher (Apache)
>  wrote:
>> On 14.04.2021 13:25, Mark Thomas wrote:
>>> On 14/04/2021 12:22, Rony G. Flatscher (Apache) wrote:
 Not finding any pointers, asking here: is it possible to define 
 environment variables for a webapp?
 If so, how?
>>> You can only set them globally, for the Java process - not per web 
>>> application.
>>>
>>> CGI creates a new process so can have a completely different set of 
>>> environment variables.
>>>
>>> How about using the per web application JNDI context?
>> Well the idea was to adjust PATH to have it point to a webapp based 
>> directory containing the
>> binaries. :)
>>
>> ---rony
>>
>> P.S.: The aim would be to make it simple and easy for deploying webapps that 
>> also need to have
>> access to non-Java binaries (executables and/or shared libraries).
>>
>>
>>


-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Defining environment variables for a webapp ?

2021-04-14 Thread Martynas Jusevičius
Rony,

you might want to look into containerizing your webapps. We use an
XSLT stylesheet (invoked by the entrypoint script) that transforms env
params into context.xml params:
https://github.com/AtomGraph/LinkedDataHub/blob/master/platform/context.xsl


Martynas

On Wed, Apr 14, 2021 at 2:16 PM Rony G. Flatscher (Apache)
 wrote:
>
> On 14.04.2021 13:25, Mark Thomas wrote:
> > On 14/04/2021 12:22, Rony G. Flatscher (Apache) wrote:
> >> Not finding any pointers, asking here: is it possible to define 
> >> environment variables for a webapp?
> >> If so, how?
> >
> > You can only set them globally, for the Java process - not per web 
> > application.
> >
> > CGI creates a new process so can have a completely different set of 
> > environment variables.
> >
> > How about using the per web application JNDI context?
>
> Well the idea was to adjust PATH to have it point to a webapp based directory 
> containing the
> binaries. :)
>
> ---rony
>
> P.S.: The aim would be to make it simple and easy for deploying webapps that 
> also need to have
> access to non-Java binaries (executables and/or shared libraries).
>
>
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Defining environment variables for a webapp ?

2021-04-14 Thread Rony G. Flatscher (Apache)
On 14.04.2021 13:25, Mark Thomas wrote:
> On 14/04/2021 12:22, Rony G. Flatscher (Apache) wrote:
>> Not finding any pointers, asking here: is it possible to define environment 
>> variables for a webapp?
>> If so, how?
>
> You can only set them globally, for the Java process - not per web 
> application.
>
> CGI creates a new process so can have a completely different set of 
> environment variables.
>
> How about using the per web application JNDI context?

Well the idea was to adjust PATH to have it point to a webapp based directory 
containing the
binaries. :)

---rony

P.S.: The aim would be to make it simple and easy for deploying webapps that 
also need to have
access to non-Java binaries (executables and/or shared libraries).



-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Re: Defining environment variables for a webapp ?

2021-04-14 Thread Mark Thomas

On 14/04/2021 12:22, Rony G. Flatscher (Apache) wrote:

Not finding any pointers, asking here: is it possible to define environment 
variables for a webapp?
If so, how?


You can only set them globally, for the Java process - not per web 
application.


CGI creates a new process so can have a completely different set of 
environment variables.


How about using the per web application JNDI context?

Mark




---rony

P.S.: Tomcat can manipulate the process' environment, e.g. in the case of CGI 
execution. Here a
sample of the process' environment from some CGI-invocation on a Windows 
machine:

 (debug) current cgi process environment:||

  1. |AUTH_TYPE=
  2. COMSPEC=C:\WINDOWS\SysWOW64\CMD.EXE
  3. CONTENT_LENGTH=7
  4. CONTENT_TYPE=application/x-www-form-urlencoded
  5. GATEWAY_INTERFACE=CGI/1.1
  6. 
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
  7. HTTP_ACCEPT_ENCODING=gzip, deflate
  8. HTTP_ACCEPT_LANGUAGE=en-US,en;q=0.5
  9. HTTP_COOKIE=JSESSIONID=2137ECEC8CC5EE35AEFA475E5C5D8250
 10. HTTP_HOST=localhost:8080
 11. 
HTTP_REFERER=http://localhost:8080/demoSTL-Core-SQL_ooRexx/JSTL_CGI_05-GroupWorkDivider.jsp
 12. HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) 
Gecko/20100101 Firefox/87.0
 13. PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC
 14. PATH_INFO=
 15. PROMPT=$P$G
 16. 
QUERY_STRING=name=Andreas+Burgstaller&name=Max+Mustermann&name=Nadine+Berger&name=Klaus+Karter&name=Simon+Hauser&name=Michael+Nimmervoll
 17. REMOTE_ADDR=127.0.0.1
 18. REMOTE_HOST=127.0.0.1
 19. REMOTE_IDENT=
 20. REMOTE_USER=
 21. REQUEST_METHOD=POST
 22. REQUEST_URI=/demoSTL-Core-SQL_ooRexx/cgi-bin/groupStudents.rexx
 23. RXQUEUESESSION=3B1C
 24. SCRIPT_FILENAME=D:\Apache Software Foundation\Tomcat
 9.0\webapps\demoSTL-Core-SQL_ooRexx\WEB-INF\cgi\groupStudents.rexx
 25. SCRIPT_NAME=/demoSTL-Core-SQL_ooRexx/cgi-bin/groupStudents.rexx
 26. SERVER_NAME=localhost
 27. SERVER_PORT=8080
 28. SERVER_PROTOCOL=HTTP/1.1
 29. SERVER_SOFTWARE=TOMCAT
 30. SystemRoot=C:\WINDOWS
 31. X_TOMCAT_SCRIPT_PATH=D:\Apache Software Foundation\Tomcat
 9.0\webapps\demoSTL-Core-SQL_ooRexx\WEB-INF\cgi\groupStudents.rexx
 |






-
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



Defining environment variables for a webapp ?

2021-04-14 Thread Rony G. Flatscher (Apache)
Not finding any pointers, asking here: is it possible to define environment 
variables for a webapp?
If so, how?

---rony

P.S.: Tomcat can manipulate the process' environment, e.g. in the case of CGI 
execution. Here a
sample of the process' environment from some CGI-invocation on a Windows 
machine:

(debug) current cgi process environment:||

 1. |AUTH_TYPE=
 2. COMSPEC=C:\WINDOWS\SysWOW64\CMD.EXE
 3. CONTENT_LENGTH=7
 4. CONTENT_TYPE=application/x-www-form-urlencoded
 5. GATEWAY_INTERFACE=CGI/1.1
 6. 
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
 7. HTTP_ACCEPT_ENCODING=gzip, deflate
 8. HTTP_ACCEPT_LANGUAGE=en-US,en;q=0.5
 9. HTTP_COOKIE=JSESSIONID=2137ECEC8CC5EE35AEFA475E5C5D8250
10. HTTP_HOST=localhost:8080
11. 
HTTP_REFERER=http://localhost:8080/demoSTL-Core-SQL_ooRexx/JSTL_CGI_05-GroupWorkDivider.jsp
12. HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:87.0) 
Gecko/20100101 Firefox/87.0
13. PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.JS;.WS;.MSC
14. PATH_INFO=
15. PROMPT=$P$G
16. 
QUERY_STRING=name=Andreas+Burgstaller&name=Max+Mustermann&name=Nadine+Berger&name=Klaus+Karter&name=Simon+Hauser&name=Michael+Nimmervoll
17. REMOTE_ADDR=127.0.0.1
18. REMOTE_HOST=127.0.0.1
19. REMOTE_IDENT=
20. REMOTE_USER=
21. REQUEST_METHOD=POST
22. REQUEST_URI=/demoSTL-Core-SQL_ooRexx/cgi-bin/groupStudents.rexx
23. RXQUEUESESSION=3B1C
24. SCRIPT_FILENAME=D:\Apache Software Foundation\Tomcat
9.0\webapps\demoSTL-Core-SQL_ooRexx\WEB-INF\cgi\groupStudents.rexx
25. SCRIPT_NAME=/demoSTL-Core-SQL_ooRexx/cgi-bin/groupStudents.rexx
26. SERVER_NAME=localhost
27. SERVER_PORT=8080
28. SERVER_PROTOCOL=HTTP/1.1
29. SERVER_SOFTWARE=TOMCAT
30. SystemRoot=C:\WINDOWS
31. X_TOMCAT_SCRIPT_PATH=D:\Apache Software Foundation\Tomcat
9.0\webapps\demoSTL-Core-SQL_ooRexx\WEB-INF\cgi\groupStudents.rexx
|