tornado - 程序部分中的主管配置用户选项

标签 tornado supervisord

我有一个 Tornado 程序,并且所有相关的 python 库都安装在名为 bob 的非 root 用户中:

pip install --user xxx

现在我想在主管中运行它:

[program:testpro]
command=python /path/to/myfile.py
user=bob    ; set the user to bob
redirect_stderr=true
stdout_logfile=/path/to/log
numproces=1
autostart=true

但是失败了,处于supervisorctl状态:

testpro            FATAL     Exited too quickly (process log may have details)

我查看日志,发现它无法导入相对的 python 库,因此它不能以 bob 身份运行。

然后我更改为:

[program:testpro]
command=sudo -u bob -i python /path/to/myfile.py
;user=bob ;comment this
redirect_stderr=true
stdout_logfile=/path/to/log
numproces=1
autostart=true

运行正常

那么,选项user有什么作用呢?以及如何在选项中配置运行用户?

最佳答案

我已经解决了这个问题:

在程序部分添加环境选项:

environment=HOME="/home/bob",USER="bob"

参见Supervisor doc - Subprocess Environment :

No shell is executed by supervisord when it runs a subprocess, so environment variables such as USER, PATH, HOME, SHELL, LOGNAME, etc. are not changed from their defaults or otherwise reassigned. This is particularly important to note when you are running a program from a supervisord run as root with a user= stanza in the configuration. Unlike cron, supervisord does not attempt to divine and override “fundamental” environment variables like USER, PATH, HOME, and LOGNAME when it performs a setuid to the user defined within the user= program config option. If you need to set environment variables for a particular program that might otherwise be set by a shell invocation for a particular user, you must do it explicitly within the environment= program config option. An example of setting these enviroment variables is as below.

[program:apache2]
command=/home/chrism/bin/httpd -c "ErrorLog
/dev/stdout" -DFOREGROUND user=chrism
environment=HOME="/home/chrism",USER="chrism"

关于tornado - 程序部分中的主管配置用户选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27291448/

相关文章:

python - Tornado 多进程: create multiple MySQL connections

python - 如何在 Tornado 中处理对文件的 HTTP GET 请求?

python - 在 Elastic Beanstalk 上使用 Supervisor 和 Django 将 Celery 作为守护进程运行

python - Django rq 的 Supervisord 配置不起作用

apache-spark - 如何使用 Supervisord 自动启动 Apache Spark 集群?

if-statement - Tornado 中的 if...else 语句

python - 如何在同一测试用例中使用假设和基于 pytest-tornado 产量的测试?

node.js - 防止开发人员无意中杀死本地计算机上的守护进程/工作进程

elementtree - 无法在centos 5.2上安装supervisord 3.1.3

python - 从 Tornado 开始