Friday, 6 September 2013

Use virtualenv as root in a python web project on production

Use virtualenv as root in a python web project on production

So I have the following configuration:
Nginx server with uWsgi
Django project in a virtualenv
My virtualenv is owned by an ordinal system user and the whole
configuration works fine! The uwsgi process is configured to run with
nginx uid & gid, as well as the nginx process owner in the nginx.conf.
But, if I try to use another virtualenv satisfying the same requirements,
but owned by root, my uwsgi can't locate the virtualenv, throwing an
import error.
Is this normal and is my aproach correct to use a root owned virtualenv?
Edit:
uwsgi config:
[uwsgi]
virtualenv = /root/Envs/rootenv
thread = 4
uid = nginx
gid = nginx
env = DJANGO_SETTINGS_MODULE=myServer.settings
module = django.core.handlers.wsgi:WSGIHandler()
chdir = /var/www/myServer
socket = /var/run/uwsgi/myserver.sock
logto = /var/log/uwsgi/myserver.log
/root/.bashrc:
### Virtualenv settings ###
export WORKON_HOME=/root/Envs
source /usr/local/bin/virtualenvwrapper.sh
export PIP_VIRTUALENV_BASE=$WORKON_HOME
export PIP_RESPECT_VIRTUALENV=true
uwsgi
*** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:02:41 2013] ***
compiled with version: 4.7.2 on 06 September 2013 10:59:26
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
nodename: myserver3
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /
detected binary path: /usr/local/bin/uwsgi
setgid() to 32
set additional group 4 (adm)
setuid() to 32
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7929
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
Python version: 2.7.3 (default, Jan 2 2013, 14:09:21) [GCC 4.7.2]
Set PythonHome to /root/Envs/rootenv
ImportError: No module named site
*** Starting uWSGI 1.9.15 (64bit) on [Fri Sep 6 14:03:13 2013] ***
compiled with version: 4.7.2 on 06 September 2013 10:59:26
os: Linux-3.2.0-4-amd64 #1 SMP Debian 3.2.41-2+deb7u2
nodename: myserver3
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 2
current working directory: /
detected binary path: /usr/local/bin/uwsgi
setgid() to 32
set additional group 4 (adm)
setuid() to 32
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 7929
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
uwsgi socket 0 bound to UNIX address /var/run/uwsgi/myserver.sock fd 3
Python version: 2.7.3 (default, Jan 2 2013, 14:09:21) [GCC 4.7.2]
Set PythonHome to /root/Envs/rootenv
ImportError: No module named site
Iknow, I'm running uWSGI without its master process manager, and there is
a reason for that :)

No comments:

Post a Comment