Domanda

This is my application environment:

Redhat 6.0
Apache 2.2
Django 1.3.0
Python 2.6.6
cx_Oracle 5.1
mod_wsgi 3.2
Oracle DBMS 11.2 (on a different machine)

Issue: accessing my django website from a web browser fails because cx_Oracle can't acquire Oracle handle.

Tests:

  1. running django-admin.py shell to query the db DOES WORK (running from a bash session with ORACLE_HOME and LD_LIBRARY_PATH vars set)
  2. running a custom script that adds ORACLE_HOME and LD_LIBRARY_PATH to os.environ and uses cx_Oracle to connect to DB, without using django DOES WORK (running from a bash session with ORACLE_HOME and LD_LIBRARY_PATH vars set)
  3. running the same custom script with "sudo -u apache" does NOT work
  4. running the same custom script with "sudo -u env ORACLE_HOME=foo LD_LIBRARY_PATH=foo myscript.py" DOES WORK
  5. modifying django.db.backends.oracle.base.py so that, before the Database.connect statement, I have os.environ printed to a file, SHOWS I HAVE ORACLE_HOME AND LD_LIBRARY_PATH CORRECTLY SET
  6. explicitly setting ORACLE_HOME and LD_LIBRARY_PATH in os.environment inside adhoc django wsgi.py script DOES NOT WORK
  7. restarting httpd with "sudo env ORACLE_HOME=foo LD_LIBRARY_PATH=foo /etc/init.d/httpd restart" DOES WORK

My question is: why is test 7 different from tests 2, 5, 6? To put it another way, why do I have to pass env vars to parent httpd process instead of just setting them in python/django scripts?

È stato utile?

Soluzione

The LD_LIBRARY_PATH must be in the environment prior to a process being executed. The process runtime loader will only read it once at startup, changing the value of the environment after the process has been started makes no difference. This is just how things work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top