I'm using OpenShift, and I'm using the custom hooks. Mainly:
- start (application start)
- stop (application stop)
- pre_build
- post_deploy
For reasons of I've-already-tried, I'm not using 3rd-party cartridges serving python/nginx (It gives me several errors out of this topic).
So I had to stick on manually installing nginx, and ensuring that starts and stops accordingly.
Now: My application uses nginx because I need websockets, and the best library I found is fairly modern. So for my application I must use gunicorn
and django-gevent-websockets
.
For many language issues, I rejected using shell script but instead I used python:
#!/usr/bin/env python
...
And, after doing complex tasks, I run by os.system
many commands with the following logic:
- start the virtual environment
- install a recent gunicorn (if it's not installed)
- install the websockets library (if it's not installed)
- leave the virtual environment
- pkill httpd processes
- start nginx
Always echoing those commands to console (print
ing them). But I found an error:
sh: command deactivate not found.
This means: at the moment of executing that command, somehow we were not in the virtualenv. I don't know if I'm right with this, but seems that os.system
creates a different environment for each call, so: after the start the virtualenv
step, I'm not anymore in the virtual env.
Question: How can I preserve the shell context across calls, so the activate
call has effect in subsequent system calls? This means: I want to be able to put those packages in the virtualenv, and execute related stuff.
This OpenShift application uses a Python cartridge (shipped with Apache).