0

when I run sudo -E supervisor reread/reload

I have the command defined in the [program:site] section to launch the 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"

it will showed up the error .

I set DJANGO_WEATHER_STATION_HOST in the /etc/profile.d/project.sh

project.sh

export DJANGO_WEATHER_STATION_HOST=the_host_ip

After reloading it but in vain.

I also set in the ~/.profile

But still got the error.

File "/home/nhcc/campus-weather-station/weather_station/gunicorn.conf.py", line 5, in bind = "{}:8080".format(os.environ['DJANGO_WEATHER_STATION_HOST']) File "/usr/lib/python3.5/os.py", line 725, in getitem raise KeyError(key) from None KeyError: 'DJANGO_WEATHER_STATION_HOST'

Jonathan Cheng
  • 459
  • 2
  • 11
  • 26
  • Supervisord needs env variables to be specified inside it's configuration. Refer to: http://supervisord.org/configuration.html#environment-variables – Wiggy A. Sep 23 '17 at 13:00
  • Possible duplicates of https://stackoverflow.com/questions/12900402/supervisor-and-environment-variables – Amit Yadav Sep 23 '17 at 13:01
  • Mabe I didn't descript clearly.But my problem is about the python environment variable part.After running the supervisor command the python file called.And the error showed up. – Jonathan Cheng Sep 23 '17 at 14:07

1 Answers1

2

Supervisor maintains its own environment.

Read here more. http://supervisord.org/subprocess.html#subprocess-environment

So you have to pass environment in /etc/supervisor/conf.d/weather.conf file.

Ex of /etc/supervisor/conf.d/weather.conf with env set.

[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"
Amit Yadav
  • 1,861
  • 2
  • 20
  • 27
  • Mabe I didn't descript clearly.But my problem is about the python environment variable part.After running the supervisor command the python file called.And the error showed up. – Jonathan Cheng Sep 23 '17 at 14:07