我的意思不是在 supervisord.conf
文件中,而是 - 当您通过 supervisorctl restart procname
启动/重新启动某个进程时。我试过 ENVTEST=something supervisorctl start env-test
但没有用。
这里有一些我所拥有的:
supervisord.conf:
[program:env-test]
command=python env_test.py
stdout_logfile=logs/env_test.log
autostart=false
env_test.py:
import os
print('envtest:', os.environ.get('ENVTEST'))
我尝试过的命令:ENVTEST=something supervisorctl start env-test
我想到的解决方案是让我的程序使用一些 env 文件并在重新启动之前更改它。
非常感谢!
答案 0 :(得分:0)
到目前为止,我选择了:
pip install python-dotenv
env_test.py:
import os
from dotenv import load_dotenv
load_dotenv()
print('envtest:', os.environ.get('ENVTEST'))
.env 文件:
ENVTEST=something
并像往常一样启动它:supervisorctl start env-test
通过这种方式,python 代码可以使用该变量。