Python 如何在Supervisor服务中设置环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17055951/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set environment variables in Supervisor service
提问by Cerin
How do you export environment variables in the command executed by Supervisor? I first tried:
在Supervisor执行的命令中如何导出环境变量?我第一次尝试:
command="export SITE=domain1; python manage.py command"
but Supervisor reports "can't find command".
但主管报告“找不到命令”。
So then I tried:
然后我尝试了:
command=/bin/bash -c "export SITE=domain1; python manage.py command"
and the command runs, but this seems to interfere with the daemonization since when I stop the Supervisor daemon, all the other daemons it's running aren't stopped.
并且命令运行,但这似乎干扰了守护进程,因为当我停止主管守护进程时,它正在运行的所有其他守护进程都没有停止。
回答by neko_ua
Just do it separately:
单独做:
environment=SITE=domain1
command=python manage.py command
Refer to http://supervisord.org/subprocess.html#subprocess-environmentfor more info.
有关更多信息,请参阅http://supervisord.org/subprocess.html#subprocess-environment。
回答by ChillarAnand
To add a single environment variable, You can do something like this.
要添加单个环境变量,您可以执行以下操作。
[program:django]
environment=SITE=domain1
command = python manage.py command
But, if you want to export multiple environment variables, you need to separate them by comma.
但是,如果要导出多个环境变量,则需要用逗号分隔它们。
[program:django]
environment =
SITE=domain1,
DJANGO_SETTINGS_MODULE=foo.settings.local,
DB_USER=foo,
DB_PASS=bar
command = python manage.py command

