0

I'm going through the "Getting Started with Openshift" guide trying to learn this stuff. I have successfully added and configured a postgres db in my python gear.

If I run an env on the gear itself, I see the database environment variables:

[]\> env |grep POSTGRESQL_DB
OPENSHIFT_POSTGRESQL_DB_HOST=x.x.x.x
OPENSHIFT_POSTGRESQL_DB_USERNAME=admindb
OPENSHIFT_POSTGRESQL_DB_PORT=5432

But in my deployed code, I dump all the env variables with logging.error(os.environ) and none of the POSTGRESQL_DB variables are set. All the python ones seem to load properly.

I know I could set these vars manually, but since these vars are controlled by the gear they could become stale. The documentation implies that these variables should be set (they are used in the sample code).

2 Answers 2

1

Found the problem.

In the instructions we set a hot_deploy marker (so the application doesn't bounce when code changes are committed). The next step in the instructions is to add the postgres cartridge, but the environment variables won't load until the cartridge is restarted. So bounce the application and all is well.

Thanks, Ryan

Sign up to request clarification or add additional context in comments.

Comments

0

Is your deployed code running through the same logged-in shell environment as you log in with?

A common solution to making code see shell environment variables that are launched via some non-shell method is to launch them through a login shell.

For example:

/bin/bash -lc "/whatever/you/are/launching --args stuff"

1 Comment

Thanks for the response. Nope, the code is deployed and run via OpenShift. As far as I know I don't have any control over how it is launched, but the OpenShift cartridge is supposed to set a ste of preconfigured variables for use in the application (OPENSHIFT_POSTGRES_DB_HOST, among others).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.