主管和环境变量

我真的不知道如何让主管处理环境变量。

下面是一个配置片段。

[program:htNotificationService]
priority=2
#autostart=true
#autorestart=true
directory=/home/ubuntu/workspace/htFrontEnd/heythat/htsite
command = /usr/bin/python htNotificationService.py -service
stdout_logfile=/var/log/heythat/htNotificationService.log
redirect_stderr=true
environment=PATH=/home/ubuntu/workspace/htFrontEnd/heythat
stopsignal=QUIT

我试过以下方法:

environment=PATH=/home/ubuntu/workspace/htFrontEnd/heythat
environment=PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat
environment=PATH=/home/ubuntu/workspace/htFrontEnd/heythat,PYTHONPATH=$PYTHONPATH:/home/ubuntu/workspace/htFrontEnd/heythat

当我开始当主管的时候

htNotificationService: ERROR (abnormal termination)

我可以通过设置 python 路径从 shell 开始,但不能从 monitor 开始。在日志中,我得到一个错误,说明找不到导入。如果主管能工作的话,问题就解决了。我甚至有/etc/环境中的路径?

为什么主管不工作?

109831 次浏览

Referencing existing env vars is done with %(ENV_VARNAME)s

See: https://github.com/Supervisor/supervisor/blob/master/supervisor/skel/sample.conf

Setting multiple environment variables is done by separating them with commas

See: http://supervisord.org/subprocess.html#subprocess-environment

Try:

environment=PYTHONPATH=/opt/mypypath:%(ENV_PYTHONPATH)s,PATH=/opt/mypath:%(ENV_PATH)s

In your .conf file under the supervisord block, you can add all the environment key=value pairs as such

[supervisord]
environment=CELERY_BROKER_URL="amqp://guest:guest@127.0.0.1:5672//",FLASK_CONFIG="TESTING"


[program:celeryd]
command=celery worker -A celery --loglevel=info -P gevent -c 1000

If you dont want to hardcode the variables but want to pull it in from the os environment, step 1 on your bash

Export env var

>> sudo export CELERY_BROKER_URL="amqp://guest:guest@127.0.0.1:5672//"

Reload Bash

>> . ~/.bashrc

Check if env vars are set properly

>> env

Now modify the conf file to read - Note: prepend your env variables with ENV_

[supervisord]
environment=CELERY_BROKER_URL="%(ENV_CELERY_BROKER_URL)s",FLASK_CONFIG="%(ENV_FLASK_CONFIG)s"


[program:celeryd]
command=celery worker -A celery --loglevel=info -P gevent -c 1000

If you install supervisor from a package installer, check which Supervisor version you are using. As of August 2016 you will get 3.0b2. If this is the case you will need a newer version of supervisor. You can get it by installing supervisor manually or by using Python's pip. Make sure all the dependencies are met, along with the upstart setup so that supervisord works as a service and starts on system boot.

this works for me. note the tabs before each line:

environment=
CLOUD_INSTANCE_NAME=media-server-xx-xx-xx-xx,
CLOUD_APPLICATION=media-server,
CLOUD_APP_COMPONENT=none,
CLOUD_ZONE=a,
CLOUD_REGION=b,
CLOUD_PRIVATE_IP=none,
CLOUD_PUBLIC_IP=xx.xx.xx.xx,
CLOUD_PUBLIC_IPV6=xx.xx.xx.xx.xx.xx,
CLOUD_PROVIDER=c

I know this is old but I just struggled with this for hours and wanted to maybe help out the next guy.

Don't forget to reload your config files after making updates

supervisorctl reread
supervisorctl update