whoami=subprocess.check_output(['/bin/whoami'])
pwd=subprocess.check_output(['/bin/pwd'])
date=subprocess.check_output(['/bin/date'])
envStr=""
for key in os.environ.keys():
envStr = envStr + '<B>' + key + '</b> is set to <B>' + os.environ[key] + '</b><br>\n'
statusStr="File operation <B>OK</b>"
try:
file=open('/usr/local/apacheTest/testTimes.dat', 'a')
file.write(date)
file.close()
except:
statusStr="File operation <B>FAILED</b>"
return ['<html><body>In WSGI test script with env :<br>' + envStr +
'<br><br>/bin/pwd returned : ' + pwd +
'<br>/bin/whoami returned : ' + whoami +
'<br><br>' + statusStr + '<br><br>' +
date + '</body></html>']
And the result is that is shows this :
http://netdrms02.nispdc.nso.edu/apacheTest/Or, to cut-and-paste that web page into this reply, it shows that the wsgi script is being run by user apache with a minimal path and environment, and that the attempt to write to a file in the apacheTest/ directory (which is owned by apache - I made sure of that!) fails. So that web page looks like this :
In WSGI test script with env :
LANG is set to
C
PATH is set to
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin
NOTIFY_SOCKET is set to
/run/systemd/notify
/bin/pwd returned : /
/bin/whoami returned : apache
File operation
FAILEDTue Feb 13 12:46:55 MST 2018
The thing is, I can "su -m apache" and then cd into that directory and run a python script that is essentially a copy of the wsgiTest.wsgi (but run as main rather than as a function) and it all just works. I don't see anything in the apache error logs, either.
I know everyone said to run tracd under strace, and really, THANK YOU for that suggestion, but I wanted to try this first. It seems like it's something in the Apache setup? Or the configuration of mod_wsgi? And I can't see what, although I'm not very familiar with either of those things.
Any thoughts/suggestions appreciated!