uWSGI set configuration depending on environment variable

瘦欲@ 提交于 2019-12-10 16:26:15

问题


Please help me understand uWSGI configuration logic. I have an environment variable ENVIRONMENT. Let's say its values can either be dev or prod. I want to set configuration options based on value of ENVIRONMENT

# always executes print statement, doesn't matter what ENVIRONMENT is set to
if-env= ENVIRONMENT
if-opt: %(_)=dev
print = RUNNING %(_)
endif:
endif =

# always executes print statement, doesn't matter what ENVIRONMENT is set to
running = ENVIRONMENT
if-opt: running=dev
print = RUNNING %(_)
endif:

I would assume if ENVIRONMENT is set to prod none of the assignments or print statements inside if-opt block would execute. But this not the case.


回答1:


This should work:

[uwsgi]
if-env = ENVIRONMENT
env = %(_)
endif =
if-not-env = ENVIRONMENT
env = none
endif =
print = RUNNING %(env)
if-opt = env=dev
print = running dev yay
endif =

You were using YAML syntax in INI configuration. I also had to take if-opt out of if-env because it was complaining about recursion. There might be a way to make it shorter, but this works.



来源:https://stackoverflow.com/questions/47091122/uwsgi-set-configuration-depending-on-environment-variable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!