繁体   English   中英

Python无法使用Supervisor读取环境变量

[英]Python can't read the environment variable with Supervisor

当我运行sudo -Esupervisor reread / reload

我在[program:site]部分中定义了命令来启动gunicorn.conf.py

/etc/supervisor/conf.d/weather.conf

[program:site]
directory=/home/nhcc/campus-weather-station/weather_station
command=/home/nhcc/venv/weather_station/bin/gunicorn -c /home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py -p gunicorn.pod weather_station.wsgi

gunicorn.conf.py

# -*- coding: utf-8 -*-
# /usr/bin/python3
import os

bind = "{}:8080".format(os.environ['DJANGO_WEATHER_STATION_HOST'])
worders = (os.sysconf('SC_NPROCESSORS_ONLN') * 2) + 1
loglevel = 'error'
command = "WTR_VENV/gunicorn"
pythonpath = "$PROJECT/weather_station"

它会显示错误。

我在/etc/profile.d/project.sh中设置了DJANGO_WEATHER_STATION_HOST

project.sh

export DJANGO_WEATHER_STATION_HOST=the_host_ip

重新加载后,但徒劳无功。

我也在〜/ .profile中设置

但是仍然出现错误。

文件“ /home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py”,第5行,在bind =“ {}:8080” .format(os.environ ['DJANGO_WEATHER_STATION_HOST'])文件“ / usr /lib/python3.5/os.py“,第725行,在getitem中从None引发KeyError (key):Keyword:'DJANGO_WEATHER_STATION_HOST'

主管维护自己的环境。

在这里阅读更多。 http://supervisord.org/subprocess.html#subprocess-environment

因此,您必须在/etc/supervisor/conf.d/weather.conf文件中传递环境。

的当然/etc/supervisor/conf.d/weather.confenv集。

[program:site]
directory=/home/nhcc/campus-weather-station/weather_station
command=/home/nhcc/venv/weather_station/bin/gunicorn -c /home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py -p gunicorn.pod weather_station.wsgi

environment=HOME="/home/chrism",USER="chrism"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM