Linux 以 root 身份运行 Celery

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20346851/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 01:31:45  来源:igfitidea点击:

Running Celery as root

linuxdjangocelery

提问by ATOzTOA

I need to run my Django along with Celery as root for access reasons. It says I need to set C_FORCE_ROOT environment variable. How/where do I set the environment variable?

出于访问原因,我需要以 root 身份运行我的 Django 和 Celery。它说我需要设置 C_FORCE_ROOT 环境变量。如何/在哪里设置环境变量?

采纳答案by securecurve

You can set it to true like this:

您可以像这样将其设置为 true:

# export C_FORCE_ROOT="true"

Then make sure it is set as an env. variable

然后确保将其设置为 env。多变的

# echo $C_FORCE_ROOT
true

But make sure to make it permanent, as this will vanish with the next restart

但请确保将其永久化,因为下次重新启动时它会消失

Have fun :) !!

玩得开心 :) !!

回答by Krzysztof Szularz

Anywhere so the python process picks it up by using os.environ.

在任何地方,python 进程都可以使用os.environ.

If your question is about how the environment variables work, please read this tutorial.

如果您的问题是关于环境变量如何工作,请阅读本教程

回答by Chemical Programmer

1st solution- Manually type command at terminal

第一个解决方案- 在终端手动输入命令

$ export C_FORCE_ROOT='true'


2nd solution- Edit shell configuration

第二种解决方案- 编辑外壳配置

$ vi ~/.bashrc

    # add following line
    export C_FORCE_ROOT='true'

$ source ~/.bashrc


3rd solution- Edit manage.pyof Django

第三种解决方案- manage.pyDjango 的编辑

import os 

if __name__ == '__main__':
    os.environ.setdefault('C_FORCE_ROOT', 'true')
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', '{PATH TO SETTINGS FILE}')

    execute_from_command_line(sys.argv)