【问题标题】:Python can't read the environment variable with SupervisorPython无法使用Supervisor读取环境变量
【发布时间】:2018-03-04 22:12:11
【问题描述】:

当我运行 sudo -E supervisor 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

项目.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 中 从无 KeyError 提高 KeyError(key): 'DJANGO_WEATHER_STATION_HOST'

【问题讨论】:

标签: python linux django


【解决方案1】:

主管维护自己的环境。

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

所以你必须在/etc/supervisor/conf.d/weather.conf文件中传递环境。

/etc/supervisor/conf.d/weather.conf 的前env 设置。

[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"

【讨论】:

  • Mabe我没有描述清楚。但我的问题是关于python环境变量部分。运行supervisor命令后调用python文件。错误出现了。
猜你喜欢
  • 2019-11-21
  • 2014-08-16
  • 2019-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-03
  • 1970-01-01
相关资源
最近更新 更多