python - Unable to start Django/Gunicorn via Supervisor -
i'm trying start django project on debian server using supervisor , gunicorn. when run command "sudo supervisorctl start gunicorn", i'm getting following error:
traceback (most recent call last): file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 507, in spawn_worker worker.init_process() file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 118, in init_process self.wsgi = self.app.wsgi() file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi self.callable = self.load() file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load return self.load_wsgiapp() file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp return util.import_app(self.app_uri) file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/gunicorn/util.py", line 355, in import_app __import__(module) file "/srv/http/example.com/repo/conf/wsgi.py", line 28, in <module> application = get_wsgi_application() file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application django.setup() file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/django/__init__.py", line 17, in setup configure_logging(settings.logging_config, settings.logging) file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/django/conf/__init__.py", line 48, in __getattr__ self._setup(name) file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/django/conf/__init__.py", line 44, in _setup self._wrapped = settings(settings_module) file "/home/smith/venvs/hash1/local/lib/python2.7/site-packages/django/conf/__init__.py", line 92, in __init__ mod = importlib.import_module(self.settings_module) file "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) file "/srv/http/example.com/repo/conf/settings/prod.py", line 2, in <module> conf.settings.base import * file "/srv/http/example.com/repo/conf/settings/base.py", line 128, in <module> media_root = get_env_variable('media_root') file "/srv/http/example.com/repo/conf/settings/base.py", line 23, in get_env_variable raise improperlyconfigured(error_msg) improperlyconfigured: set media_root environment variable [2016-01-27 19:39:31 +0000] [30408] [info] worker exiting (pid: 30408) my base.py base settings file reads environment variables set in "hash1" virtual environment's postactivate hook:
# base.py def get_env_variable(var_name): try: return os.environ[var_name] except keyerror: error_msg = "set %s environment variable" % var_name raise improperlyconfigured(error_msg) # rest of settings... i've confirmed "improperlyconfigured" error message being generated function in settings file.
here supervisor , gunicorn files:
# /etc/supervisor/conf.d/supervisor.conf [program:gunicorn] command=/srv/http/example.com/repo/bin/start-gunicorn directory=/srv/http/example.com/repo user=root environment=media_root="/var/www/swing/media/" # start-gunicorn #!/bin/bash name=example djangodir=/srv/http/example.com/repo user=smith group=smith website=$name num_workers=3 django_settings_module=conf.settings.prod django_wsgi_module=conf.wsgi cd /home/smith/venvs/current/bin source activate export django_settings_module=$django_settings_module export pythonpath=$djangodir:$pythonpath exec gunicorn ${django_wsgi_module}:application \ --name $name \ --workers $num_workers \ --user=$user \ --group=$group \ --bind=127.0.0.1:8000 \ --access-logfile /var/log/gunicorn/access.log \ --error-logfile /var/log/gunicorn/error.log \ --pid /var/tmp/gunicorn.pid \ --log-level=info i using default wsgi.py , supervisord.conf files. versions follows:
django 1.8.4 debian 8.2 supervisor 3.0r1-1 (installed globally) gunicorn 19.3.0 (installed in virtual environment "hash1") can see i'm doing wrong? wouldn't expect supervisor see environment variables why i've set media_root variable via supervisor's "environment" parameter. supervisor still doesn't seem seeing it. able start gunicorn when run start-gunicorn script command line. know i'm doing stupid can't see it.
thanks!
i not sure, think problem defining media_root in root user environment, run program smith user , doesn't have media_root defined in environment. maybe can try editing base.py
def get_env_variable(var_name): try: return os.environ[var_name] except keyerror: error_msg = "set %s environment variable" % var_name # debugging process append username , environment vars error_msg user = os.environ['user'] env_vars = os.environ.keys() error_msg += " current user: %s env_vars: %s" % (user, env_vars) raise improperlyconfigured(error_msg) then start django , check error message check if user has media_root defined in environment.
Comments
Post a Comment